Skip to content

Commit 6a5227b

Browse files
committed
Fix TypeError related to issue #3
1 parent c92be28 commit 6a5227b

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/Detector/AbstractDetector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected function trim(string $str): string|array|null
254254
/**
255255
* Replace given string using map data.
256256
* @param string $str
257-
* @param array<string, mixed> $maps
257+
* @param array<string|int, mixed> $maps
258258
* @return string|null
259259
*/
260260
protected function str(string $str, array $maps): ?string
@@ -268,7 +268,11 @@ protected function str(string $str, array $maps): ?string
268268
}
269269
}
270270
} elseif (strpos($value, $str) !== false) {
271-
return $key === self::UNKNOWN ? null : $key;
271+
if ($key === self::UNKNOWN || is_string($key) === false) {
272+
return null;
273+
}
274+
275+
return $key;
272276
}
273277
}
274278

tests/UserAgentTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,54 @@ public function testAll(
6262
public function allTestsDataProvider(): array
6363
{
6464
return [
65+
[
66+
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Xbox; Xbox One)',
67+
10,
68+
'IE',
69+
'10.0',
70+
'',
71+
'Xbox',
72+
'console',
73+
'Microsoft',
74+
'Trident',
75+
6,
76+
'6.0',
77+
0,
78+
'Windows',
79+
'',
80+
],
81+
[
82+
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)',
83+
9,
84+
'IE',
85+
'9.0',
86+
'',
87+
'Xbox',
88+
'console',
89+
'Microsoft',
90+
'Trident',
91+
5,
92+
'5.0',
93+
0,
94+
'Windows',
95+
'',
96+
],
97+
[
98+
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b',
99+
534,
100+
'WebKit',
101+
'534',
102+
'amd64',
103+
'',
104+
'',
105+
'',
106+
'WebKit',
107+
534,
108+
'534',
109+
0,
110+
'Windows',
111+
'',
112+
],
65113
[
66114
'mwb-db-client Opera/9.80 (Linux armv7l ; U; HbbTV/1.1.1 (; TOSHIBA; 32SL863; 19.2.39.208; 3; ) ; ToshibaTP/1.1.1 () ; en) Presto/2.6.33 Version/10.60',
67115
10,

0 commit comments

Comments
 (0)