Skip to content

Commit

Permalink
Hide macOS version, if it is a known fixed number
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsLeenheer committed Apr 17, 2024
1 parent d8c8f9e commit 9608721
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/Analyser/Corrections.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,37 @@ private function &applyCorrections()
$this->hideFamilyIfEqualToBrowser();
}

if (isset($this->data->browser->name) && isset($this->data->os->name) && isset($this->data->os->version)) {
$this->hideOsVersionIfFixed();
}

return $this;
}


private function hideOsVersionIfFixed()
{
if ($this->data->os->name == 'OS X') {
$name = $this->data->browser->name;

if (isset($this->data->browser->family)) {
$name = $this->data->browser->family->name;
}

if ($name == 'Chrome' && $this->data->os->version->value == "10.15.7") {
$this->data->os->version = null;
}

if ($name == 'Safari' && $this->data->os->version->value == "10.15.7") {
$this->data->os->version = null;
}

if ($name == 'Firefox' && $this->data->os->version->value == "10.15") {
$this->data->os->version = null;
}
}
}

private function hideFamilyIfEqualToBrowser()
{
if ($this->data->browser->name == $this->data->browser->family->name) {
Expand Down
8 changes: 6 additions & 2 deletions tests/data/desktop/browser-chrome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@
readable: 'Chrome 87 on macOS Big Sur 11.0'
-
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'
readable: 'Chrome 100 on macOS Catalina 10.15'
result: { browser: { name: Chrome, version: '100', type: browser }, engine: { name: Blink }, os: { name: 'OS X', alias: macOS, version: { value: '10.15', nickname: Catalina } }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
readable: 'Chrome 100 on macOS'
result: { browser: { name: Chrome, version: '100', type: browser }, engine: { name: Blink }, os: { name: 'OS X', alias: macOS }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
-
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
readable: 'Chrome 123 on macOS'
result: { browser: { name: Chrome, version: '123', type: browser }, engine: { name: Blink }, os: { name: 'OS X', alias: macOS }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
4 changes: 4 additions & 0 deletions tests/data/desktop/browser-edge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3782.0 Safari/537.36 Edg/76.0.152.0'
readable: 'Edge 76 on macOS Mojave 10.14'
result: { browser: { name: Edge, family: { name: Chrome, version: 76 }, version: '76', type: browser }, engine: { name: Blink }, os: { name: 'OS X', alias: macOS, version: { value: '10.14', nickname: Mojave } }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
-
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0'
readable: 'Edge 123 on macOS'
result: { browser: { name: Edge, family: { name: Chrome, version: 123 }, version: '123', type: browser }, engine: { name: Blink }, os: { name: 'OS X', alias: macOS }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
4 changes: 4 additions & 0 deletions tests/data/desktop/browser-firefox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,7 @@
headers: 'User-Agent: Mozilla/5.0 (X11; U; Darwin i386; en-US; rv:1.9.1.4) Gecko/20100311 Shiretoko/3.5.5'
readable: 'Firefox Shiretoko 3.5.5 on Darwin'
result: { browser: { name: Firefox, version: 3.5.5, type: browser }, engine: { name: Gecko, version: 1.9.1 }, os: { name: Darwin }, device: { type: desktop } }
-
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0'
readable: 'Firefox 123.0 on macOS'
result: { browser: { name: Firefox, version: '123.0', type: browser }, engine: { name: Gecko, version: '123.0' }, os: { name: 'OS X', alias: macOS }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
4 changes: 4 additions & 0 deletions tests/data/desktop/browser-safari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15'
readable: 'Safari 14.0.1 on macOS Catalina 10.15'
result: { browser: { name: Safari, version: 14.0.1, type: browser }, engine: { name: Webkit, version: 605.1.15 }, os: { name: 'OS X', alias: macOS, version: { value: '10.15', nickname: Catalina } }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }
-
headers: 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15'
readable: 'Safari 17.5 on macOS'
result: { browser: { name: Safari, version: '17.5', type: browser }, engine: { name: Webkit, version: 605.1.15 }, os: { name: 'OS X', alias: macOS }, device: { type: desktop, manufacturer: Apple, model: Macintosh } }

0 comments on commit 9608721

Please sign in to comment.