From 888650ee382a6cad5be27820cfa1486aa6ac2d3a Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Tue, 27 Aug 2024 09:08:07 +0100 Subject: [PATCH 1/2] Fix bug where the OS name cannot be determined from the user agent. --- src/Classes/UserAgent/ParserPhpDriver.php | 2 +- tests/Unit/Classes/ResolverTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Classes/UserAgent/ParserPhpDriver.php b/src/Classes/UserAgent/ParserPhpDriver.php index 10757a0..12f825c 100644 --- a/src/Classes/UserAgent/ParserPhpDriver.php +++ b/src/Classes/UserAgent/ParserPhpDriver.php @@ -24,7 +24,7 @@ public function getOperatingSystem(): ?string return null; } - return $this->parser->os->name ?: null; + return $this->parser->os->name ?? null; } public function getOperatingSystemVersion(): ?string diff --git a/tests/Unit/Classes/ResolverTest.php b/tests/Unit/Classes/ResolverTest.php index 343d24f..663df5f 100644 --- a/tests/Unit/Classes/ResolverTest.php +++ b/tests/Unit/Classes/ResolverTest.php @@ -84,6 +84,19 @@ public static function trackingFieldsProvider(): array 'device_type' => 'robot', ], ], + + // UC Browser 7 + [ + 'Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999', + [ + 'operating_system' => null, + 'operating_system_version' => null, + 'browser' => 'UC Browser', + 'browser_version' => '7.0', + 'referer_url' => null, + 'device_type' => 'mobile', + ], + ], ]; } From bb8c1a3f7c85770024a0f017ee3d3fcec0559d6d Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Tue, 27 Aug 2024 09:14:33 +0100 Subject: [PATCH 2/2] Ignore PHPStan error. --- src/Classes/UserAgent/ParserPhpDriver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Classes/UserAgent/ParserPhpDriver.php b/src/Classes/UserAgent/ParserPhpDriver.php index 12f825c..73218e9 100644 --- a/src/Classes/UserAgent/ParserPhpDriver.php +++ b/src/Classes/UserAgent/ParserPhpDriver.php @@ -24,6 +24,7 @@ public function getOperatingSystem(): ?string return null; } + /** @phpstan-ignore-next-line */ return $this->parser->os->name ?? null; }