Completed
Push — master ( 84d414...7917f0 )
by Gabriel
02:29
created

BrowserDetector::checkBrowserYandex()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 15
loc 15
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Sinergi\BrowserDetector;
4
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 3 View Code Duplication
    public static function checkBrowserBlackBerry()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
124
    {
125 3
        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 2
        return false;
137
    }
138
139
    /**
140
     * Determine if the browser is a robot.
141
     *
142
     * @return bool
143
     */
144 2
    public static function checkBrowserRobot()
145
    {
146 2
        if (stripos(self::$userAgentString, 'bot') !== false ||
147 2
            stripos(self::$userAgentString, 'spider') !== false ||
148 2
            stripos(self::$userAgentString, 'crawler') !== false
149 2
        ) {
150
            self::$browser->setIsRobot(true);
151
152
            return true;
153
        }
154
155 2
        return false;
156
    }
157
158
    /**
159
     * Determine if the browser is Internet Explorer.
160
     *
161
     * @return bool
162
     */
163 7
    public static function checkBrowserInternetExplorer()
164
    {
165
        // Test for v1 - v1.5 IE
166 7
        if (stripos(self::$userAgentString, 'microsoft internet explorer') !== false) {
167
            self::$browser->setName(Browser::IE);
168
            self::$browser->setVersion('1.0');
169
            $aresult = stristr(self::$userAgentString, '/');
170
            if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
171
                self::$browser->setVersion('1.5');
172
            }
173
174
            return true;
175
        } // Test for versions > 1.5 and < 11 and some cases of 11
176
        else {
177 7
            if (stripos(self::$userAgentString, 'msie') !== false && stripos(self::$userAgentString, 'opera') === false
178 7
            ) {
179
                // See if the browser is the odd MSN Explorer
180 2 View Code Duplication
                if (stripos(self::$userAgentString, 'msnb') !== false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
181
                    $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'MSN'));
182
                    self::$browser->setName(Browser::MSN);
183
                    if (isset($aresult[1])) {
184
                        self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
185
                    }
186
187
                    return true;
188
                }
189 2
                $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'msie'));
190 2
                self::$browser->setName(Browser::IE);
191 2
                if (isset($aresult[1])) {
192 2
                    self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
193 2
                }
194
                // See https://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx
195
                // Might be 11, anyway !
196 2
                if (stripos(self::$userAgentString, 'trident') !== false) {
197 2
                    preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches);
198 2
                    if (isset($matches[1])) {
199 1
                        self::$browser->setVersion($matches[1]);
200 1
                    }
201
202
                    // At this poing in the method, we know the MSIE and Trident
203
                    // strings are present in the $userAgentString. If we're in
204
                    // compatibility mode, we need to determine the true version.
205
                    // If the MSIE version is 7.0, we can look at the Trident
206
                    // version to *approximate* the true IE version. If we don't
207
                    // find a matching pair, ( e.g. MSIE 7.0 && Trident/7.0 )
208
                    // we're *not* in compatibility mode and the browser really
209
                    // is version 7.0.
210 2
                    if (stripos(self::$userAgentString, 'MSIE 7.0;')) {
211 1
                        if (stripos(self::$userAgentString, 'Trident/7.0;')) {
212
                            // IE11 in compatibility mode
213 1
                            self::$browser->setVersion('11.0');
214 1
                            self::$browser->setIsCompatibilityMode(true);
215 1
                        } elseif (stripos(self::$userAgentString, 'Trident/6.0;')) {
216
                            // IE10 in compatibility mode
217 1
                            self::$browser->setVersion('10.0');
218 1
                            self::$browser->setIsCompatibilityMode(true);
219 1
                        } elseif (stripos(self::$userAgentString, 'Trident/5.0;')) {
220
                            // IE9 in compatibility mode
221 1
                            self::$browser->setVersion('9.0');
222 1
                            self::$browser->setIsCompatibilityMode(true);
223 1
                        } elseif (stripos(self::$userAgentString, 'Trident/4.0;')) {
224
                            // IE8 in compatibility mode
225 1
                            self::$browser->setVersion('8.0');
226 1
                            self::$browser->setIsCompatibilityMode(true);
227 1
                        }
228 1
                    }
229 2
                }
230
231 2
                return true;
232
            } // Test for versions >= 11
233
            else {
234 7
                if (stripos(self::$userAgentString, 'trident') !== false) {
235 1
                    self::$browser->setName(Browser::IE);
236
237 1
                    preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches);
238 1
                    if (isset($matches[1])) {
239 1
                        self::$browser->setVersion($matches[1]);
240
241 1
                        return true;
242
                    } else {
243
                        return false;
244
                    }
245
                } // Test for Pocket IE
246
                else {
247 6
                    if (stripos(self::$userAgentString, 'mspie') !== false ||
248 6
                        stripos(
249 6
                            self::$userAgentString,
250
                            'pocket'
251 6
                        ) !== false
252 6
                    ) {
253
                        $aresult = explode(' ', stristr(self::$userAgentString, 'mspie'));
254
                        self::$browser->setName(Browser::POCKET_IE);
255
256
                        if (stripos(self::$userAgentString, 'mspie') !== false) {
257
                            if (isset($aresult[1])) {
258
                                self::$browser->setVersion($aresult[1]);
259
                            }
260
                        } else {
261
                            $aversion = explode('/', self::$userAgentString);
262
                            if (isset($aversion[1])) {
263
                                self::$browser->setVersion($aversion[1]);
264
                            }
265
                        }
266
267
                        return true;
268
                    }
269
                }
270
            }
271
        }
272
273 6
        return false;
274
    }
275
276
    /**
277
     * Determine if the browser is Opera.
278
     *
279
     * @return bool
280
     */
281 6
    public static function checkBrowserOpera()
282
    {
283 6
        if (stripos(self::$userAgentString, 'opera mini') !== false) {
284
            $resultant = stristr(self::$userAgentString, 'opera mini');
285
            if (preg_match('/\//', $resultant)) {
286
                $aresult = explode('/', $resultant);
287
                if (isset($aresult[1])) {
288
                    $aversion = explode(' ', $aresult[1]);
289
                    self::$browser->setVersion($aversion[0]);
290
                }
291
            } else {
292
                $aversion = explode(' ', stristr($resultant, 'opera mini'));
293
                if (isset($aversion[1])) {
294
                    self::$browser->setVersion($aversion[1]);
295
                }
296
            }
297
            self::$browser->setName(Browser::OPERA_MINI);
298
299
            return true;
300 6
        } elseif (stripos(self::$userAgentString, 'OPiOS') !== false) {
301 1
            $aresult = explode('/', stristr(self::$userAgentString, 'OPiOS'));
302 1
            if (isset($aresult[1])) {
303 1
                $aversion = explode(' ', $aresult[1]);
304 1
                self::$browser->setVersion($aversion[0]);
305 1
            }
306 1
            self::$browser->setName(Browser::OPERA_MINI);
307
308 1
            return true;
309 6
        } elseif (stripos(self::$userAgentString, 'opera') !== false) {
310 1
            $resultant = stristr(self::$userAgentString, 'opera');
311 1
            if (preg_match('/Version\/(1[0-2].*)$/', $resultant, $matches)) {
312 1
                if (isset($matches[1])) {
313 1
                    self::$browser->setVersion($matches[1]);
314 1
                }
315 1
            } elseif (preg_match('/\//', $resultant)) {
316
                $aresult = explode('/', str_replace('(', ' ', $resultant));
317
                if (isset($aresult[1])) {
318
                    $aversion = explode(' ', $aresult[1]);
319
                    self::$browser->setVersion($aversion[0]);
320
                }
321
            } else {
322 1
                $aversion = explode(' ', stristr($resultant, 'opera'));
323 1
                self::$browser->setVersion(isset($aversion[1]) ? $aversion[1] : '');
324
            }
325 1
            self::$browser->setName(Browser::OPERA);
326
327 1
            return true;
328 5
        } elseif (stripos(self::$userAgentString, ' OPR/') !== false) {
329 1
            self::$browser->setName(Browser::OPERA);
330 1
            if (preg_match('/OPR\/([\d\.]*)/', self::$userAgentString, $matches)) {
331 1
                if (isset($matches[1])) {
332 1
                    self::$browser->setVersion($matches[1]);
333 1
                }
334 1
            }
335
336 1
            return true;
337
        }
338
339 5
        return false;
340
    }
341
342
    /**
343
     * Determine if the browser is Chrome.
344
     *
345
     * @return bool
346
     */
347 3
    public static function checkBrowserChrome()
348
    {
349 3
        if (stripos(self::$userAgentString, 'Chrome') !== false) {
350 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Chrome'));
351 1
            if (isset($aresult[1])) {
352 1
                $aversion = explode(' ', $aresult[1]);
353 1
                self::$browser->setVersion($aversion[0]);
354 1
            }
355 1
            self::$browser->setName(Browser::CHROME);
356
357 1
            return true;
358 3
        } elseif (stripos(self::$userAgentString, 'CriOS') !== false) {
359 1
            $aresult = explode('/', stristr(self::$userAgentString, 'CriOS'));
360 1
            if (isset($aresult[1])) {
361 1
                $aversion = explode(' ', $aresult[1]);
362 1
                self::$browser->setVersion($aversion[0]);
363 1
            }
364 1
            self::$browser->setName(Browser::CHROME);
365
366 1
            return true;
367
        }
368
369 3
        return false;
370
    }
371
372
    /**
373
     * Determine if the browser is Vivaldi.
374
     *
375
     * @return bool
376
     */
377 5 View Code Duplication
    public static function checkBrowserVivaldi()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
378
    {
379 5
        if (stripos(self::$userAgentString, 'Vivaldi') !== false) {
380 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Vivaldi'));
381 1
            if (isset($aresult[1])) {
382 1
                $aversion = explode(' ', $aresult[1]);
383 1
                self::$browser->setVersion($aversion[0]);
384 1
            }
385 1
            self::$browser->setName(Browser::VIVALDI);
386
387 1
            return true;
388
        }
389
390 5
        return false;
391
    }
392
393
    /**
394
     * Determine if the browser is Microsoft Edge.
395
     *
396
     * @return bool
397
     */
398 6
    public static function checkBrowserEdge()
399
    {
400 6
        if (stripos(self::$userAgentString, 'Edge') !== false) {
401 1
            $version = explode('Edge/', self::$userAgentString);
402 1
            if (isset($version[1])) {
403 1
                self::$browser->setVersion((float)$version[1]);
404 1
            }
405 1
            self::$browser->setName(Browser::EDGE);
406
407 1
            return true;
408
        }
409
410 6
        return false;
411
    }
412
413
    /**
414
     * Determine if the browser is Google Search Appliance.
415
     *
416
     * @return bool
417
     */
418 2 View Code Duplication
    public static function checkBrowserGsa()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
419
    {
420 2
        if (stripos(self::$userAgentString, 'GSA') !== false) {
421
            $aresult = explode('/', stristr(self::$userAgentString, 'GSA'));
422
            if (isset($aresult[1])) {
423
                $aversion = explode(' ', $aresult[1]);
424
                self::$browser->setVersion($aversion[0]);
425
            }
426
            self::$browser->setName(Browser::GSA);
427
428
            return true;
429
        }
430
431 2
        return false;
432
    }
433
434
    /**
435
     * Determine if the browser is WebTv.
436
     *
437
     * @return bool
438
     */
439 7 View Code Duplication
    public static function checkBrowserWebTv()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
440
    {
441 7
        if (stripos(self::$userAgentString, 'webtv') !== false) {
442
            $aresult = explode('/', stristr(self::$userAgentString, 'webtv'));
443
            if (isset($aresult[1])) {
444
                $aversion = explode(' ', $aresult[1]);
445
                self::$browser->setVersion($aversion[0]);
446
            }
447
            self::$browser->setName(Browser::WEBTV);
448
449
            return true;
450
        }
451
452 7
        return false;
453
    }
454
455
    /**
456
     * Determine if the browser is NetPositive.
457
     *
458
     * @return bool
459
     */
460 1
    public static function checkBrowserNetPositive()
461
    {
462 1 View Code Duplication
        if (stripos(self::$userAgentString, 'NetPositive') !== false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
463
            $aresult = explode('/', stristr(self::$userAgentString, 'NetPositive'));
464
            if (isset($aresult[1])) {
465
                $aversion = explode(' ', $aresult[1]);
466
                self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
467
            }
468
            self::$browser->setName(Browser::NETPOSITIVE);
469
470
            return true;
471
        }
472
473 1
        return false;
474
    }
475
476
    /**
477
     * Determine if the browser is Galeon.
478
     *
479
     * @return bool
480
     */
481 5 View Code Duplication
    public static function checkBrowserGaleon()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
482
    {
483 5
        if (stripos(self::$userAgentString, 'galeon') !== false) {
484
            $aresult = explode(' ', stristr(self::$userAgentString, 'galeon'));
485
            $aversion = explode('/', $aresult[0]);
486
            if (isset($aversion[1])) {
487
                self::$browser->setVersion($aversion[1]);
488
            }
489
            self::$browser->setName(Browser::GALEON);
490
491
            return true;
492
        }
493
494 5
        return false;
495
    }
496
497
    /**
498
     * Determine if the browser is Konqueror.
499
     *
500
     * @return bool
501
     */
502 1 View Code Duplication
    public static function checkBrowserKonqueror()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
503
    {
504 1
        if (stripos(self::$userAgentString, 'Konqueror') !== false) {
505
            $aresult = explode(' ', stristr(self::$userAgentString, 'Konqueror'));
506
            $aversion = explode('/', $aresult[0]);
507
            if (isset($aversion[1])) {
508
                self::$browser->setVersion($aversion[1]);
509
            }
510
            self::$browser->setName(Browser::KONQUEROR);
511
512
            return true;
513
        }
514
515 1
        return false;
516
    }
517
518
    /**
519
     * Determine if the browser is iCab.
520
     *
521
     * @return bool
522
     */
523 1 View Code Duplication
    public static function checkBrowserIcab()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
524
    {
525 1
        if (stripos(self::$userAgentString, 'icab') !== false) {
526
            $aversion = explode(' ', stristr(str_replace('/', ' ', self::$userAgentString), 'icab'));
527
            if (isset($aversion[1])) {
528
                self::$browser->setVersion($aversion[1]);
529
            }
530
            self::$browser->setName(Browser::ICAB);
531
532
            return true;
533
        }
534
535 1
        return false;
536
    }
537
538
    /**
539
     * Determine if the browser is OmniWeb.
540
     *
541
     * @return bool
542
     */
543 3 View Code Duplication
    public static function checkBrowserOmniWeb()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
544
    {
545 3
        if (stripos(self::$userAgentString, 'omniweb') !== false) {
546
            $aresult = explode('/', stristr(self::$userAgentString, 'omniweb'));
547
            $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : '');
548
            self::$browser->setVersion($aversion[0]);
549
            self::$browser->setName(Browser::OMNIWEB);
550
551
            return true;
552
        }
553
554 3
        return false;
555
    }
556
557
    /**
558
     * Determine if the browser is Phoenix.
559
     *
560
     * @return bool
561
     */
562 1
    public static function checkBrowserPhoenix()
563
    {
564 1
        if (stripos(self::$userAgentString, 'Phoenix') !== false) {
565
            $aversion = explode('/', stristr(self::$userAgentString, 'Phoenix'));
566
            if (isset($aversion[1])) {
567
                self::$browser->setVersion($aversion[1]);
568
            }
569
            self::$browser->setName(Browser::PHOENIX);
570
571
            return true;
572
        }
573
574 1
        return false;
575
    }
576
577
    /**
578
     * Determine if the browser is Firebird.
579
     *
580
     * @return bool
581
     */
582 1
    public static function checkBrowserFirebird()
583
    {
584 1
        if (stripos(self::$userAgentString, 'Firebird') !== false) {
585
            $aversion = explode('/', stristr(self::$userAgentString, 'Firebird'));
586
            if (isset($aversion[1])) {
587
                self::$browser->setVersion($aversion[1]);
588
            }
589
            self::$browser->setName(Browser::FIREBIRD);
590
591
            return true;
592
        }
593
594 1
        return false;
595
    }
596
597
    /**
598
     * Determine if the browser is Netscape Navigator 9+.
599
     *
600
     * @return bool
601
     */
602 5
    public static function checkBrowserNetscapeNavigator9Plus()
603
    {
604 5
        if (stripos(self::$userAgentString, 'Firefox') !== false &&
605 2
            preg_match('/Navigator\/([^ ]*)/i', self::$userAgentString, $matches)
606 5
        ) {
607
            if (isset($matches[1])) {
608
                self::$browser->setVersion($matches[1]);
609
            }
610
            self::$browser->setName(Browser::NETSCAPE_NAVIGATOR);
611
612
            return true;
613 5
        } elseif (stripos(self::$userAgentString, 'Firefox') === false &&
614 4
            preg_match('/Netscape6?\/([^ ]*)/i', self::$userAgentString, $matches)
615 5
        ) {
616
            if (isset($matches[1])) {
617
                self::$browser->setVersion($matches[1]);
618
            }
619
            self::$browser->setName(Browser::NETSCAPE_NAVIGATOR);
620
621
            return true;
622
        }
623
624 5
        return false;
625
    }
626
627
    /**
628
     * Determine if the browser is Shiretoko.
629
     *
630
     * @return bool
631
     */
632 1
    public static function checkBrowserShiretoko()
633
    {
634 1
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
635
            preg_match('/Shiretoko\/([^ ]*)/i', self::$userAgentString, $matches)
636 1
        ) {
637
            if (isset($matches[1])) {
638
                self::$browser->setVersion($matches[1]);
639
            }
640
            self::$browser->setName(Browser::SHIRETOKO);
641
642
            return true;
643
        }
644
645 1
        return false;
646
    }
647
648
    /**
649
     * Determine if the browser is Ice Cat.
650
     *
651
     * @return bool
652
     */
653 1
    public static function checkBrowserIceCat()
654
    {
655 1
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
656
            preg_match('/IceCat\/([^ ]*)/i', self::$userAgentString, $matches)
657 1
        ) {
658
            if (isset($matches[1])) {
659
                self::$browser->setVersion($matches[1]);
660
            }
661
            self::$browser->setName(Browser::ICECAT);
662
663
            return true;
664
        }
665
666 1
        return false;
667
    }
668
669
    /**
670
     * Determine if the browser is Nokia.
671
     *
672
     * @return bool
673
     */
674 2
    public static function checkBrowserNokia()
675
    {
676 2
        if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", self::$userAgentString, $matches)) {
677
            self::$browser->setVersion($matches[2]);
678
            if (stripos(self::$userAgentString, 'Series60') !== false ||
679
                strpos(self::$userAgentString, 'S60') !== false
680
            ) {
681
                self::$browser->setName(Browser::NOKIA_S60);
682
            } else {
683
                self::$browser->setName(Browser::NOKIA);
684
            }
685
686
            return true;
687
        }
688
689 2
        return false;
690
    }
691
692
    /**
693
     * Determine if the browser is Firefox.
694
     *
695
     * @return bool
696
     */
697 4 View Code Duplication
    public static function checkBrowserFirefox()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
698
    {
699 4
        if (stripos(self::$userAgentString, 'safari') === false) {
700 4
            if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) {
701 2
                if (isset($matches[1])) {
702 2
                    self::$browser->setVersion($matches[1]);
703 2
                }
704 2
                self::$browser->setName(Browser::FIREFOX);
705
706 2
                return true;
707 2
            } elseif (preg_match('/Firefox$/i', self::$userAgentString, $matches)) {
708
                self::$browser->setVersion('');
709
                self::$browser->setName(Browser::FIREFOX);
710
711
                return true;
712
            }
713 2
        }
714
715 3
        return false;
716
    }
717
718
    /**
719
     * Determine if the browser is SeaMonkey.
720
     *
721
     * @return bool
722
     */
723 5 View Code Duplication
    public static function checkBrowserSeaMonkey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
724
    {
725 5
        if (stripos(self::$userAgentString, 'safari') === false) {
726 5
            if (preg_match("/SeaMonkey[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) {
727 1
                if (isset($matches[1])) {
728 1
                    self::$browser->setVersion($matches[1]);
729 1
                }
730 1
                self::$browser->setName(Browser::SEAMONKEY);
731
732 1
                return true;
733 4
            } elseif (preg_match('/SeaMonkey$/i', self::$userAgentString, $matches)) {
734
                self::$browser->setVersion('');
735
                self::$browser->setName(Browser::SEAMONKEY);
736
737
                return true;
738
            }
739 4
        }
740
741 4
        return false;
742
    }
743
744
    /**
745
     * Determine if the browser is Iceweasel.
746
     *
747
     * @return bool
748
     */
749 1 View Code Duplication
    public static function checkBrowserIceweasel()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
750
    {
751 1
        if (stripos(self::$userAgentString, 'Iceweasel') !== false) {
752
            $aresult = explode('/', stristr(self::$userAgentString, 'Iceweasel'));
753
            if (isset($aresult[1])) {
754
                $aversion = explode(' ', $aresult[1]);
755
                self::$browser->setVersion($aversion[0]);
756
            }
757
            self::$browser->setName(Browser::ICEWEASEL);
758
759
            return true;
760
        }
761
762 1
        return false;
763
    }
764
765
    /**
766
     * Determine if the browser is Mozilla.
767
     *
768
     * @return bool
769
     */
770 1
    public static function checkBrowserMozilla()
771
    {
772 1
        if (stripos(self::$userAgentString, 'mozilla') !== false &&
773 1
            preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString) &&
774
            stripos(self::$userAgentString, 'netscape') === false
775 1
        ) {
776
            $aversion = explode(' ', stristr(self::$userAgentString, 'rv:'));
777
            preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString, $aversion);
778
            self::$browser->setVersion(str_replace('rv:', '', $aversion[0]));
779
            self::$browser->setName(Browser::MOZILLA);
780
781
            return true;
782 1
        } elseif (stripos(self::$userAgentString, 'mozilla') !== false &&
783 1
            preg_match('/rv:[0-9]\.[0-9]/i', self::$userAgentString) &&
784
            stripos(self::$userAgentString, 'netscape') === false
785 1
        ) {
786
            $aversion = explode('', stristr(self::$userAgentString, 'rv:'));
787
            self::$browser->setVersion(str_replace('rv:', '', $aversion[0]));
788
            self::$browser->setName(Browser::MOZILLA);
789
790
            return true;
791 1
        } elseif (stripos(self::$userAgentString, 'mozilla') !== false &&
792 1
            preg_match('/mozilla\/([^ ]*)/i', self::$userAgentString, $matches) &&
793
            stripos(self::$userAgentString, 'netscape') === false
794 1
        ) {
795
            if (isset($matches[1])) {
796
                self::$browser->setVersion($matches[1]);
797
            }
798
            self::$browser->setName(Browser::MOZILLA);
799
800
            return true;
801
        }
802
803 1
        return false;
804
    }
805
806
    /**
807
     * Determine if the browser is Lynx.
808
     *
809
     * @return bool
810
     */
811 1 View Code Duplication
    public static function checkBrowserLynx()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
812
    {
813 1
        if (stripos(self::$userAgentString, 'lynx') !== false) {
814
            $aresult = explode('/', stristr(self::$userAgentString, 'Lynx'));
815
            $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ''));
816
            self::$browser->setVersion($aversion[0]);
817
            self::$browser->setName(Browser::LYNX);
818
819
            return true;
820
        }
821
822 1
        return false;
823
    }
824
825
    /**
826
     * Determine if the browser is Amaya.
827
     *
828
     * @return bool
829
     */
830 1 View Code Duplication
    public static function checkBrowserAmaya()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
831
    {
832 1
        if (stripos(self::$userAgentString, 'amaya') !== false) {
833
            $aresult = explode('/', stristr(self::$userAgentString, 'Amaya'));
834
            if (isset($aresult[1])) {
835
                $aversion = explode(' ', $aresult[1]);
836
                self::$browser->setVersion($aversion[0]);
837
            }
838
            self::$browser->setName(Browser::AMAYA);
839
840
            return true;
841
        }
842
843 1
        return false;
844
    }
845
846
    /**
847
     * Determine if the browser is Safari.
848
     *
849
     * @return bool
850
     */
851 2
    public static function checkBrowserSafari()
852
    {
853 2
        if (stripos(self::$userAgentString, 'Safari') !== false) {
854 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Version'));
855 1
            if (isset($aresult[1])) {
856 1
                $aversion = explode(' ', $aresult[1]);
857 1
                self::$browser->setVersion($aversion[0]);
858 1
            } else {
859
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
860
            }
861 1
            self::$browser->setName(Browser::SAFARI);
862
863 1
            return true;
864
        }
865
866 1
        return false;
867
    }
868
869
    /**
870
     * Determine if the browser is Yandex.
871
     *
872
     * @return bool
873
     */
874 3 View Code Duplication
    public static function checkBrowserYandex()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
875
    {
876 3
        if (stripos(self::$userAgentString, 'YaBrowser') !== false) {
877 1
            $aresult = explode('/', stristr(self::$userAgentString, 'YaBrowser'));
878 1
            if (isset($aresult[1])) {
879 1
                $aversion = explode(' ', $aresult[1]);
880 1
                self::$browser->setVersion($aversion[0]);
881 1
            }
882 1
            self::$browser->setName(Browser::YANDEX);
883
884 1
            return true;
885
        }
886
887 3
        return false;
888
    }
889
890
    /**
891
     * Determine if the browser is Android.
892
     *
893
     * @return bool
894
     */
895 3
    public static function checkBrowserAndroid()
896
    {
897
        // Navigator
898 3
        if (stripos(self::$userAgentString, 'Android') !== false) {
899
            if (preg_match('/Version\/([\d\.]*)/i', self::$userAgentString, $matches)) {
900
                if (isset($matches[1])) {
901
                    self::$browser->setVersion($matches[1]);
902
                }
903
            } else {
904
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
905
            }
906
            self::$browser->setName(Browser::NAVIGATOR);
907
908
            return true;
909
        }
910
911 3
        return false;
912
    }
913
}
914