Skip to content

Commit 8c8b368

Browse files
committed
Simplify the bot dance
1 parent cbe0665 commit 8c8b368

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/UserAgentParser.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,16 @@ function parse_user_agent( $u_agent = null ) {
109109
, $u_agent, $result);
110110

111111
// If nothing matched, return null (to avoid undefined index errors)
112-
$quickReturn = false;
113-
if( !isset($result[BROWSER][0], $result[BROWSER_VERSION][0]) ) {
114-
if( preg_match('%^(?!Mozilla)(?P<browser>[A-Z0-9\-]+)([/ :](?P<version>[0-9A-Z.]+))?%ix', $u_agent, $g_result) ) {
115-
return [ PLATFORM => $platform, BROWSER => $g_result[BROWSER], BROWSER_VERSION => empty($g_result[BROWSER_VERSION]) ? null : $g_result[BROWSER_VERSION] ];
116-
}
117-
118-
$quickReturn = true;
112+
if( !isset($result[BROWSER][0], $result[BROWSER_VERSION][0])
113+
&& preg_match('%^(?!Mozilla)(?P<browser>[A-Z0-9\-]+)([/ :](?P<version>[0-9A-Z.]+))?%ix', $u_agent, $g_result) ) {
114+
return [ PLATFORM => $platform, BROWSER => $g_result[BROWSER], BROWSER_VERSION => empty($g_result[BROWSER_VERSION]) ? null : $g_result[BROWSER_VERSION] ];
119115
}
120116

121117
if(
122118
(
123119
empty($result[BROWSER][0])
124120
|| ($result['prev'][0] !== '')
125-
) // if we caught a browser, and it's the first part of the string, skip
121+
)
126122
&& preg_match(<<<'REGEX'
127123
%[(;]\s*(?P<browser>[^(/;]+)
128124
(?:[:/ ]v?(?P<version>[0-9A-Z.]+)[^;)\s]*)?
@@ -137,7 +133,7 @@ function parse_user_agent( $u_agent = null ) {
137133
];
138134
}
139135

140-
if( $quickReturn ) {
136+
if( !isset($result[BROWSER][0], $result[BROWSER_VERSION][0]) ) {
141137
return $return;
142138
}
143139

0 commit comments

Comments
 (0)