Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like BrowserDetector often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BrowserDetector, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class BrowserDetector implements DetectorInterface |
||
6 | { |
||
7 | const FUNC_PREFIX = 'checkBrowser'; |
||
8 | |||
9 | protected static $userAgentString; |
||
10 | |||
11 | /** |
||
12 | * @var Browser |
||
13 | */ |
||
14 | protected static $browser; |
||
15 | |||
16 | protected static $browsersList = array( |
||
17 | // well-known, well-used |
||
18 | // Special Notes: |
||
19 | // (1) Opera must be checked before FireFox due to the odd |
||
20 | // user agents used in some older versions of Opera |
||
21 | // (2) WebTV is strapped onto Internet Explorer so we must |
||
22 | // check for WebTV before IE |
||
23 | // (3) Because of Internet Explorer 11 using |
||
24 | // "Mozilla/5.0 ([...] Trident/7.0; rv:11.0) like Gecko" |
||
25 | // as user agent, tests for IE must be run before any |
||
26 | // tests checking for "Mozilla" |
||
27 | // (4) (deprecated) Galeon is based on Firefox and needs to be |
||
28 | // tested before Firefox is tested |
||
29 | // (5) OmniWeb is based on Safari so OmniWeb check must occur |
||
30 | // before Safari |
||
31 | // (6) Netscape 9+ is based on Firefox so Netscape checks |
||
32 | // before FireFox are necessary |
||
33 | // (7) Microsoft Edge must be checked before Chrome and Safari |
||
34 | // (7) Vivaldi must be checked before Chrome |
||
35 | 'WebTv', |
||
36 | 'InternetExplorer', |
||
37 | 'Edge', |
||
38 | 'Opera', |
||
39 | 'Vivaldi', |
||
40 | 'Galeon', |
||
41 | 'NetscapeNavigator9Plus', |
||
42 | 'SeaMonkey', |
||
43 | 'Firefox', |
||
44 | 'Yandex', |
||
45 | 'Chrome', |
||
46 | 'OmniWeb', |
||
47 | // common mobile |
||
48 | 'Android', |
||
49 | 'BlackBerry', |
||
50 | 'Nokia', |
||
51 | 'Gsa', |
||
52 | // common bots |
||
53 | 'Robot', |
||
54 | // WebKit base check (post mobile and others) |
||
55 | 'Safari', |
||
56 | // everyone else |
||
57 | 'NetPositive', |
||
58 | 'Firebird', |
||
59 | 'Konqueror', |
||
60 | 'Icab', |
||
61 | 'Phoenix', |
||
62 | 'Amaya', |
||
63 | 'Lynx', |
||
64 | 'Shiretoko', |
||
65 | 'IceCat', |
||
66 | 'Iceweasel', |
||
67 | 'Mozilla', /* Mozilla is such an open standard that you must check it last */ |
||
68 | ); |
||
69 | |||
70 | /** |
||
71 | * Routine to determine the browser type. |
||
72 | * |
||
73 | * @param Browser $browser |
||
74 | * @param UserAgent $userAgent |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | 7 | public static function detect(Browser $browser, UserAgent $userAgent = null) |
|
79 | { |
||
80 | 7 | self::$browser = $browser; |
|
81 | 7 | if (is_null($userAgent)) { |
|
82 | $userAgent = self::$browser->getUserAgent(); |
||
83 | } |
||
84 | 7 | self::$userAgentString = $userAgent->getUserAgentString(); |
|
85 | |||
86 | 7 | self::$browser->setName(Browser::UNKNOWN); |
|
87 | 7 | self::$browser->setVersion(Browser::VERSION_UNKNOWN); |
|
88 | |||
89 | 7 | self::checkChromeFrame(); |
|
90 | |||
91 | 7 | foreach (self::$browsersList as $browserName) { |
|
92 | 7 | $funcName = self::FUNC_PREFIX . $browserName; |
|
93 | |||
94 | 7 | if (self::$funcName()) { |
|
95 | 6 | return true; |
|
96 | } |
||
97 | 7 | } |
|
98 | |||
99 | 1 | return false; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * Determine if the user is using Chrome Frame. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | 7 | public static function checkChromeFrame() |
|
108 | { |
||
109 | 7 | if (strpos(self::$userAgentString, 'chromeframe') !== false) { |
|
110 | self::$browser->setIsChromeFrame(true); |
||
111 | |||
112 | return true; |
||
113 | } |
||
114 | |||
115 | 7 | return false; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Determine if the user is using a BlackBerry. |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | 2 | View Code Duplication | public static function checkBrowserBlackBerry() |
|
|||
124 | { |
||
125 | 2 | if (stripos(self::$userAgentString, 'blackberry') !== false) { |
|
126 | 1 | $aresult = explode('/', stristr(self::$userAgentString, 'BlackBerry')); |
|
127 | 1 | if (isset($aresult[1])) { |
|
128 | 1 | $aversion = explode(' ', $aresult[1]); |
|
129 | 1 | self::$browser->setVersion($aversion[0]); |
|
130 | 1 | } |
|
131 | 1 | self::$browser->setName(Browser::BLACKBERRY); |
|
132 | |||
133 | 1 | return true; |
|
134 | } |
||
135 | |||
136 | 1 | return false; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * Determine if the browser is a robot. |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 1 | public static function checkBrowserRobot() |
|
158 | |||
159 | /** |
||
160 | * Determine if the browser is Internet Explorer. |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | 7 | public static function checkBrowserInternetExplorer() |
|
165 | { |
||
166 | // Test for v1 - v1.5 IE |
||
167 | 7 | if (stripos(self::$userAgentString, 'microsoft internet explorer') !== false) { |
|
168 | self::$browser->setName(Browser::IE); |
||
169 | self::$browser->setVersion('1.0'); |
||
170 | $aresult = stristr(self::$userAgentString, '/'); |
||
171 | if (preg_match('/308|425|426|474|0b1/i', $aresult)) { |
||
172 | self::$browser->setVersion('1.5'); |
||
173 | } |
||
174 | |||
175 | return true; |
||
176 | } // Test for versions > 1.5 and < 11 and some cases of 11 |
||
177 | else { |
||
178 | 7 | if (stripos(self::$userAgentString, 'msie') !== false && stripos(self::$userAgentString, 'opera') === false |
|
179 | 7 | ) { |
|
180 | // See if the browser is the odd MSN Explorer |
||
181 | 1 | View Code Duplication | if (stripos(self::$userAgentString, 'msnb') !== false) { |
182 | $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'MSN')); |
||
183 | self::$browser->setName(Browser::MSN); |
||
184 | if (isset($aresult[1])) { |
||
185 | self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
||
186 | } |
||
187 | |||
188 | return true; |
||
189 | } |
||
190 | 1 | $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'msie')); |
|
191 | 1 | self::$browser->setName(Browser::IE); |
|
192 | 1 | if (isset($aresult[1])) { |
|
193 | 1 | self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
|
194 | 1 | } |
|
195 | // See https://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx |
||
196 | // Might be 11, anyway ! |
||
197 | 1 | if (stripos(self::$userAgentString, 'trident') !== false) { |
|
198 | 1 | preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches); |
|
199 | 1 | if (isset($matches[1])) { |
|
200 | 1 | self::$browser->setVersion($matches[1]); |
|
201 | 1 | } |
|
202 | 1 | } |
|
203 | |||
204 | 1 | return true; |
|
205 | } // Test for versions >= 11 |
||
206 | else { |
||
207 | 7 | if (stripos(self::$userAgentString, 'trident') !== false) { |
|
208 | 1 | self::$browser->setName(Browser::IE); |
|
209 | |||
210 | 1 | preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches); |
|
211 | 1 | if (isset($matches[1])) { |
|
212 | 1 | self::$browser->setVersion($matches[1]); |
|
213 | |||
214 | 1 | return true; |
|
215 | } else { |
||
216 | return false; |
||
217 | } |
||
218 | } // Test for Pocket IE |
||
219 | else { |
||
220 | 6 | if (stripos(self::$userAgentString, 'mspie') !== false || stripos(self::$userAgentString, |
|
221 | 6 | 'pocket') !== false |
|
222 | 6 | ) { |
|
223 | $aresult = explode(' ', stristr(self::$userAgentString, 'mspie')); |
||
224 | self::$browser->setName(Browser::POCKET_IE); |
||
225 | |||
226 | if (stripos(self::$userAgentString, 'mspie') !== false) { |
||
227 | if (isset($aresult[1])) { |
||
228 | self::$browser->setVersion($aresult[1]); |
||
229 | } |
||
230 | } else { |
||
231 | $aversion = explode('/', self::$userAgentString); |
||
232 | if (isset($aversion[1])) { |
||
233 | self::$browser->setVersion($aversion[1]); |
||
234 | } |
||
235 | } |
||
236 | |||
237 | return true; |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | |||
243 | 6 | return false; |
|
244 | } |
||
245 | |||
246 | /** |
||
247 | * Determine if the browser is Opera. |
||
248 | * |
||
249 | * @return bool |
||
250 | */ |
||
251 | 5 | public static function checkBrowserOpera() |
|
252 | { |
||
253 | 5 | if (stripos(self::$userAgentString, 'opera mini') !== false) { |
|
254 | $resultant = stristr(self::$userAgentString, 'opera mini'); |
||
255 | if (preg_match('/\//', $resultant)) { |
||
256 | $aresult = explode('/', $resultant); |
||
257 | if (isset($aresult[1])) { |
||
258 | $aversion = explode(' ', $aresult[1]); |
||
259 | self::$browser->setVersion($aversion[0]); |
||
260 | } |
||
261 | } else { |
||
262 | $aversion = explode(' ', stristr($resultant, 'opera mini')); |
||
263 | if (isset($aversion[1])) { |
||
264 | self::$browser->setVersion($aversion[1]); |
||
265 | } |
||
266 | } |
||
267 | self::$browser->setName(Browser::OPERA_MINI); |
||
268 | |||
269 | return true; |
||
270 | 5 | } elseif (stripos(self::$userAgentString, 'OPiOS') !== false) { |
|
271 | $aresult = explode('/', stristr(self::$userAgentString, 'OPiOS')); |
||
272 | if (isset($aresult[1])) { |
||
273 | $aversion = explode(' ', $aresult[1]); |
||
274 | self::$browser->setVersion($aversion[0]); |
||
275 | } |
||
276 | self::$browser->setName(Browser::OPERA_MINI); |
||
277 | |||
278 | return true; |
||
279 | 5 | } elseif (stripos(self::$userAgentString, 'opera') !== false) { |
|
280 | 1 | $resultant = stristr(self::$userAgentString, 'opera'); |
|
281 | 1 | if (preg_match('/Version\/(1[0-2].*)$/', $resultant, $matches)) { |
|
282 | 1 | if (isset($matches[1])) { |
|
283 | 1 | self::$browser->setVersion($matches[1]); |
|
284 | 1 | } |
|
285 | 1 | } elseif (preg_match('/\//', $resultant)) { |
|
286 | $aresult = explode('/', str_replace('(', ' ', $resultant)); |
||
287 | if (isset($aresult[1])) { |
||
288 | $aversion = explode(' ', $aresult[1]); |
||
289 | self::$browser->setVersion($aversion[0]); |
||
290 | } |
||
291 | } else { |
||
292 | 1 | $aversion = explode(' ', stristr($resultant, 'opera')); |
|
293 | 1 | self::$browser->setVersion(isset($aversion[1]) ? $aversion[1] : ''); |
|
294 | } |
||
295 | 1 | self::$browser->setName(Browser::OPERA); |
|
296 | |||
297 | 1 | return true; |
|
298 | 4 | } elseif (stripos(self::$userAgentString, ' OPR/') !== false) { |
|
299 | self::$browser->setName(Browser::OPERA); |
||
300 | if (preg_match('/OPR\/([\d\.]*)/', self::$userAgentString, $matches)) { |
||
301 | if (isset($matches[1])) { |
||
302 | self::$browser->setVersion($matches[1]); |
||
303 | } |
||
304 | } |
||
305 | |||
306 | return true; |
||
307 | } |
||
308 | |||
309 | 4 | return false; |
|
310 | } |
||
311 | |||
312 | /** |
||
313 | * Determine if the browser is Chrome. |
||
314 | * |
||
315 | * @return bool |
||
316 | */ |
||
317 | 2 | public static function checkBrowserChrome() |
|
318 | { |
||
319 | 2 | if (stripos(self::$userAgentString, 'Chrome') !== false) { |
|
320 | $aresult = explode('/', stristr(self::$userAgentString, 'Chrome')); |
||
321 | if (isset($aresult[1])) { |
||
322 | $aversion = explode(' ', $aresult[1]); |
||
323 | self::$browser->setVersion($aversion[0]); |
||
324 | } |
||
325 | self::$browser->setName(Browser::CHROME); |
||
326 | |||
327 | return true; |
||
328 | 2 | } elseif (stripos(self::$userAgentString, 'CriOS') !== false) { |
|
329 | $aresult = explode('/', stristr(self::$userAgentString, 'CriOS')); |
||
330 | if (isset($aresult[1])) { |
||
331 | $aversion = explode(' ', $aresult[1]); |
||
332 | self::$browser->setVersion($aversion[0]); |
||
333 | } |
||
334 | self::$browser->setName(Browser::CHROME); |
||
335 | |||
336 | return true; |
||
337 | } |
||
338 | |||
339 | 2 | return false; |
|
340 | } |
||
341 | |||
342 | /** |
||
343 | * Determine if the browser is Vivaldi. |
||
344 | * |
||
345 | * @return bool |
||
346 | */ |
||
347 | 4 | View Code Duplication | public static function checkBrowserVivaldi() |
348 | { |
||
349 | 4 | if (stripos(self::$userAgentString, 'Vivaldi') !== false) { |
|
350 | $aresult = explode('/', stristr(self::$userAgentString, 'Vivaldi')); |
||
351 | if (isset($aresult[1])) { |
||
352 | $aversion = explode(' ', $aresult[1]); |
||
353 | self::$browser->setVersion($aversion[0]); |
||
354 | } |
||
355 | self::$browser->setName(Browser::VIVALDI); |
||
356 | |||
357 | return true; |
||
358 | } |
||
359 | |||
360 | 4 | return false; |
|
361 | } |
||
362 | |||
363 | /** |
||
364 | * Determine if the browser is Microsoft Edge. |
||
365 | * |
||
366 | * @return bool |
||
367 | */ |
||
368 | 6 | public static function checkBrowserEdge() |
|
369 | { |
||
370 | 6 | if (stripos(self::$userAgentString, 'Edge') !== false) { |
|
371 | 1 | $version = explode('Edge/', self::$userAgentString); |
|
372 | 1 | if (isset($version[1])) { |
|
373 | 1 | self::$browser->setVersion((float)$version[1]); |
|
374 | 1 | } |
|
375 | 1 | self::$browser->setName(Browser::EDGE); |
|
376 | |||
377 | 1 | return true; |
|
378 | } |
||
379 | |||
380 | 5 | return false; |
|
381 | } |
||
382 | |||
383 | /** |
||
384 | * Determine if the browser is Google Search Appliance. |
||
385 | * |
||
386 | * @return bool |
||
387 | */ |
||
388 | 1 | View Code Duplication | public static function checkBrowserGsa() |
389 | { |
||
390 | 1 | if (stripos(self::$userAgentString, 'GSA') !== false) { |
|
391 | $aresult = explode('/', stristr(self::$userAgentString, 'GSA')); |
||
392 | if (isset($aresult[1])) { |
||
393 | $aversion = explode(' ', $aresult[1]); |
||
394 | self::$browser->setVersion($aversion[0]); |
||
395 | } |
||
396 | self::$browser->setName(Browser::GSA); |
||
397 | |||
398 | return true; |
||
399 | } |
||
400 | |||
401 | 1 | return false; |
|
402 | } |
||
403 | |||
404 | /** |
||
405 | * Determine if the browser is WebTv. |
||
406 | * |
||
407 | * @return bool |
||
408 | */ |
||
409 | 7 | View Code Duplication | public static function checkBrowserWebTv() |
410 | { |
||
411 | 7 | if (stripos(self::$userAgentString, 'webtv') !== false) { |
|
412 | $aresult = explode('/', stristr(self::$userAgentString, 'webtv')); |
||
413 | if (isset($aresult[1])) { |
||
414 | $aversion = explode(' ', $aresult[1]); |
||
415 | self::$browser->setVersion($aversion[0]); |
||
416 | } |
||
417 | self::$browser->setName(Browser::WEBTV); |
||
418 | |||
419 | return true; |
||
420 | } |
||
421 | |||
422 | 7 | return false; |
|
423 | } |
||
424 | |||
425 | /** |
||
426 | * Determine if the browser is NetPositive. |
||
427 | * |
||
428 | * @return bool |
||
429 | */ |
||
430 | 1 | public static function checkBrowserNetPositive() |
|
431 | { |
||
432 | 1 | View Code Duplication | if (stripos(self::$userAgentString, 'NetPositive') !== false) { |
433 | $aresult = explode('/', stristr(self::$userAgentString, 'NetPositive')); |
||
434 | if (isset($aresult[1])) { |
||
435 | $aversion = explode(' ', $aresult[1]); |
||
436 | self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0])); |
||
437 | } |
||
438 | self::$browser->setName(Browser::NETPOSITIVE); |
||
439 | |||
440 | return true; |
||
441 | } |
||
442 | |||
443 | 1 | return false; |
|
444 | } |
||
445 | |||
446 | /** |
||
447 | * Determine if the browser is Galeon. |
||
448 | * |
||
449 | * @return bool |
||
450 | */ |
||
451 | 4 | View Code Duplication | public static function checkBrowserGaleon() |
452 | { |
||
453 | 4 | if (stripos(self::$userAgentString, 'galeon') !== false) { |
|
454 | $aresult = explode(' ', stristr(self::$userAgentString, 'galeon')); |
||
455 | $aversion = explode('/', $aresult[0]); |
||
456 | if (isset($aversion[1])) { |
||
457 | self::$browser->setVersion($aversion[1]); |
||
458 | } |
||
459 | self::$browser->setName(Browser::GALEON); |
||
460 | |||
461 | return true; |
||
462 | } |
||
463 | |||
464 | 4 | return false; |
|
465 | } |
||
466 | |||
467 | /** |
||
468 | * Determine if the browser is Konqueror. |
||
469 | * |
||
470 | * @return bool |
||
471 | */ |
||
472 | 1 | View Code Duplication | public static function checkBrowserKonqueror() |
473 | { |
||
474 | 1 | if (stripos(self::$userAgentString, 'Konqueror') !== false) { |
|
475 | $aresult = explode(' ', stristr(self::$userAgentString, 'Konqueror')); |
||
476 | $aversion = explode('/', $aresult[0]); |
||
477 | if (isset($aversion[1])) { |
||
478 | self::$browser->setVersion($aversion[1]); |
||
479 | } |
||
480 | self::$browser->setName(Browser::KONQUEROR); |
||
481 | |||
482 | return true; |
||
483 | } |
||
484 | |||
485 | 1 | return false; |
|
486 | } |
||
487 | |||
488 | /** |
||
489 | * Determine if the browser is iCab. |
||
490 | * |
||
491 | * @return bool |
||
492 | */ |
||
493 | 1 | View Code Duplication | public static function checkBrowserIcab() |
494 | { |
||
495 | 1 | if (stripos(self::$userAgentString, 'icab') !== false) { |
|
496 | $aversion = explode(' ', stristr(str_replace('/', ' ', self::$userAgentString), 'icab')); |
||
497 | if (isset($aversion[1])) { |
||
498 | self::$browser->setVersion($aversion[1]); |
||
499 | } |
||
500 | self::$browser->setName(Browser::ICAB); |
||
501 | |||
502 | return true; |
||
503 | } |
||
504 | |||
505 | 1 | return false; |
|
506 | } |
||
507 | |||
508 | /** |
||
509 | * Determine if the browser is OmniWeb. |
||
510 | * |
||
511 | * @return bool |
||
512 | */ |
||
513 | 2 | View Code Duplication | public static function checkBrowserOmniWeb() |
514 | { |
||
515 | 2 | if (stripos(self::$userAgentString, 'omniweb') !== false) { |
|
516 | $aresult = explode('/', stristr(self::$userAgentString, 'omniweb')); |
||
517 | $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : ''); |
||
518 | self::$browser->setVersion($aversion[0]); |
||
519 | self::$browser->setName(Browser::OMNIWEB); |
||
520 | |||
521 | return true; |
||
522 | } |
||
523 | |||
524 | 2 | return false; |
|
525 | } |
||
526 | |||
527 | /** |
||
528 | * Determine if the browser is Phoenix. |
||
529 | * |
||
530 | * @return bool |
||
531 | */ |
||
532 | 1 | View Code Duplication | public static function checkBrowserPhoenix() |
533 | { |
||
534 | 1 | if (stripos(self::$userAgentString, 'Phoenix') !== false) { |
|
535 | $aversion = explode('/', stristr(self::$userAgentString, 'Phoenix')); |
||
536 | if (isset($aversion[1])) { |
||
537 | self::$browser->setVersion($aversion[1]); |
||
538 | } |
||
539 | self::$browser->setName(Browser::PHOENIX); |
||
540 | |||
541 | return true; |
||
542 | } |
||
543 | |||
544 | 1 | return false; |
|
545 | } |
||
546 | |||
547 | /** |
||
548 | * Determine if the browser is Firebird. |
||
549 | * |
||
550 | * @return bool |
||
551 | */ |
||
552 | 1 | View Code Duplication | public static function checkBrowserFirebird() |
553 | { |
||
554 | 1 | if (stripos(self::$userAgentString, 'Firebird') !== false) { |
|
555 | $aversion = explode('/', stristr(self::$userAgentString, 'Firebird')); |
||
556 | if (isset($aversion[1])) { |
||
557 | self::$browser->setVersion($aversion[1]); |
||
558 | } |
||
559 | self::$browser->setName(Browser::FIREBIRD); |
||
560 | |||
561 | return true; |
||
562 | } |
||
563 | |||
564 | 1 | return false; |
|
565 | } |
||
566 | |||
567 | /** |
||
568 | * Determine if the browser is Netscape Navigator 9+. |
||
569 | * |
||
570 | * @return bool |
||
571 | */ |
||
572 | 4 | public static function checkBrowserNetscapeNavigator9Plus() |
|
573 | { |
||
574 | 4 | if (stripos(self::$userAgentString, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', |
|
575 | 1 | self::$userAgentString, $matches) |
|
576 | 4 | ) { |
|
577 | if (isset($matches[1])) { |
||
578 | self::$browser->setVersion($matches[1]); |
||
579 | } |
||
580 | self::$browser->setName(Browser::NETSCAPE_NAVIGATOR); |
||
581 | |||
582 | return true; |
||
583 | 4 | } elseif (stripos(self::$userAgentString, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', |
|
584 | 3 | self::$userAgentString, $matches) |
|
585 | 4 | ) { |
|
586 | if (isset($matches[1])) { |
||
587 | self::$browser->setVersion($matches[1]); |
||
588 | } |
||
589 | self::$browser->setName(Browser::NETSCAPE_NAVIGATOR); |
||
590 | |||
591 | return true; |
||
592 | } |
||
593 | |||
594 | 4 | return false; |
|
595 | } |
||
596 | |||
597 | /** |
||
598 | * Determine if the browser is Shiretoko. |
||
599 | * |
||
600 | * @return bool |
||
601 | */ |
||
602 | 1 | public static function checkBrowserShiretoko() |
|
617 | |||
618 | /** |
||
619 | * Determine if the browser is Ice Cat. |
||
620 | * |
||
621 | * @return bool |
||
622 | */ |
||
623 | 1 | public static function checkBrowserIceCat() |
|
638 | |||
639 | /** |
||
640 | * Determine if the browser is Nokia. |
||
641 | * |
||
642 | * @return bool |
||
643 | */ |
||
644 | 1 | public static function checkBrowserNokia() |
|
645 | { |
||
646 | 1 | if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", self::$userAgentString, $matches)) { |
|
647 | self::$browser->setVersion($matches[2]); |
||
648 | if (stripos(self::$userAgentString, 'Series60') !== false || strpos(self::$userAgentString, |
||
649 | 'S60') !== false |
||
650 | ) { |
||
651 | self::$browser->setName(Browser::NOKIA_S60); |
||
661 | |||
662 | /** |
||
663 | * Determine if the browser is Firefox. |
||
664 | * |
||
665 | * @return bool |
||
666 | */ |
||
667 | 3 | View Code Duplication | public static function checkBrowserFirefox() |
687 | |||
688 | /** |
||
689 | * Determine if the browser is SeaMonkey. |
||
690 | * |
||
691 | * @return bool |
||
692 | */ |
||
693 | 4 | View Code Duplication | public static function checkBrowserSeaMonkey() |
713 | |||
714 | /** |
||
715 | * Determine if the browser is Iceweasel. |
||
716 | * |
||
717 | * @return bool |
||
718 | */ |
||
719 | 1 | View Code Duplication | public static function checkBrowserIceweasel() |
734 | |||
735 | /** |
||
736 | * Determine if the browser is Mozilla. |
||
737 | * |
||
738 | * @return bool |
||
739 | */ |
||
740 | 1 | public static function checkBrowserMozilla() |
|
772 | |||
773 | /** |
||
774 | * Determine if the browser is Lynx. |
||
775 | * |
||
776 | * @return bool |
||
777 | */ |
||
778 | 1 | View Code Duplication | public static function checkBrowserLynx() |
791 | |||
792 | /** |
||
793 | * Determine if the browser is Amaya. |
||
794 | * |
||
795 | * @return bool |
||
796 | */ |
||
797 | 1 | View Code Duplication | public static function checkBrowserAmaya() |
812 | |||
813 | /** |
||
814 | * Determine if the browser is Safari. |
||
815 | * |
||
816 | * @return bool |
||
817 | */ |
||
818 | 1 | View Code Duplication | public static function checkBrowserSafari() |
835 | |||
836 | /** |
||
837 | * Determine if the browser is Yandex. |
||
838 | * |
||
839 | * @return bool |
||
840 | */ |
||
841 | 2 | View Code Duplication | public static function checkBrowserYandex() |
856 | |||
857 | /** |
||
858 | * Determine if the browser is Android. |
||
859 | * |
||
860 | * @return bool |
||
861 | */ |
||
862 | 2 | View Code Duplication | public static function checkBrowserAndroid() |
880 | } |
||
881 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.