Completed
Push — master ( 8d9645...356eb6 )
by Gabriel
05:31
created

BrowserDetector::checkChromeFrame()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2.2559
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
        'Dragon',
41
        'Galeon',
42
        'NetscapeNavigator9Plus',
43
        'SeaMonkey',
44
        'Firefox',
45
        'Yandex',
46
        'Chrome',
47
        'OmniWeb',
48
        // common mobile
49
        'Android',
50
        'BlackBerry',
51
        'Nokia',
52
        'Gsa',
53
        // common bots
54
        'Robot',
55
        // WebKit base check (post mobile and others)
56
        'Safari',
57
        // everyone else
58
        'NetPositive',
59
        'Firebird',
60
        'Konqueror',
61
        'Icab',
62
        'Phoenix',
63
        'Amaya',
64
        'Lynx',
65
        'Shiretoko',
66
        'IceCat',
67
        'Iceweasel',
68
        'Mozilla', /* Mozilla is such an open standard that you must check it last */
69
    );
70
71
    /**
72
     * Routine to determine the browser type.
73
     *
74
     * @param Browser $browser
75
     * @param UserAgent $userAgent
76
     *
77
     * @return bool
78
     */
79 8
    public static function detect(Browser $browser, UserAgent $userAgent = null)
80
    {
81 8
        self::$browser = $browser;
82 8
        if (is_null($userAgent)) {
83
            $userAgent = self::$browser->getUserAgent();
84
        }
85 8
        self::$userAgentString = $userAgent->getUserAgentString();
86
87 8
        self::$browser->setName(Browser::UNKNOWN);
88 8
        self::$browser->setVersion(Browser::VERSION_UNKNOWN);
89
90 8
        self::checkChromeFrame();
91 8
        self::checkFacebookWebView();
92
93 8
        foreach (self::$browsersList as $browserName) {
94 8
            $funcName = self::FUNC_PREFIX . $browserName;
95
96 8
            if (self::$funcName()) {
97 7
                return true;
98
            }
99 8
        }
100
101 1
        return false;
102
    }
103
104
    /**
105
     * Determine if the user is using Chrome Frame.
106
     *
107
     * @return bool
108
     */
109 8
    public static function checkChromeFrame()
110
    {
111 8
        if (strpos(self::$userAgentString, 'chromeframe') !== false) {
112
            self::$browser->setIsChromeFrame(true);
113
114
            return true;
115
        }
116
117 8
        return false;
118
    }
119
120
    /**
121
     * Determine if the user is using Facebook.
122
     *
123
     * @return bool
124
     */
125 8
    public static function checkFacebookWebView()
126
    {
127 8
        if (strpos(self::$userAgentString, 'FBAV') !== false) {
128 1
            self::$browser->setIsFacebookWebView(true);
129
130 1
            return true;
131
        }
132
133 7
        return false;
134
    }
135
136
    /**
137
     * Determine if the user is using a BlackBerry.
138
     *
139
     * @return bool
140
     */
141 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...
142
    {
143 3
        if (stripos(self::$userAgentString, 'blackberry') !== false) {
144 1
            $aresult = explode('/', stristr(self::$userAgentString, 'BlackBerry'));
145 1
            if (isset($aresult[1])) {
146 1
                $aversion = explode(' ', $aresult[1]);
147 1
                self::$browser->setVersion($aversion[0]);
148 1
            }
149 1
            self::$browser->setName(Browser::BLACKBERRY);
150
151 1
            return true;
152 2
        } elseif (stripos(self::$userAgentString, 'BB10') !== false) {
153 1
            $aresult = explode('Version/10.', self::$userAgentString);
154 1
            if (isset($aresult[1])) {
155 1
                $aversion = explode(' ', $aresult[1]);
156 1
                self::$browser->setVersion('10.' . $aversion[0]);
157 1
            }
158 1
            self::$browser->setName(Browser::BLACKBERRY);
159 1
            return true;
160
        }
161
162 2
        return false;
163
    }
164
165
    /**
166
     * Determine if the browser is a robot.
167
     *
168
     * @return bool
169
     */
170 2
    public static function checkBrowserRobot()
171
    {
172 2
        if (stripos(self::$userAgentString, 'bot') !== false ||
173 2
            stripos(self::$userAgentString, 'spider') !== false ||
174 2
            stripos(self::$userAgentString, 'crawler') !== false
175 2
        ) {
176
            self::$browser->setIsRobot(true);
177
178
            return true;
179
        }
180
181 2
        return false;
182
    }
183
184
    /**
185
     * Determine if the browser is Internet Explorer.
186
     *
187
     * @return bool
188
     */
189 8
    public static function checkBrowserInternetExplorer()
190
    {
191
        // Test for v1 - v1.5 IE
192 8
        if (stripos(self::$userAgentString, 'microsoft internet explorer') !== false) {
193
            self::$browser->setName(Browser::IE);
194
            self::$browser->setVersion('1.0');
195
            $aresult = stristr(self::$userAgentString, '/');
196
            if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
197
                self::$browser->setVersion('1.5');
198
            }
199
200
            return true;
201
        } // Test for versions > 1.5 and < 11 and some cases of 11
202
        else {
203 8
            if (stripos(self::$userAgentString, 'msie') !== false && stripos(self::$userAgentString, 'opera') === false
204 8
            ) {
205
                // See if the browser is the odd MSN Explorer
206 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...
207
                    $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'MSN'));
208
                    self::$browser->setName(Browser::MSN);
209
                    if (isset($aresult[1])) {
210
                        self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
211
                    }
212
213
                    return true;
214
                }
215 2
                $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'msie'));
216 2
                self::$browser->setName(Browser::IE);
217 2
                if (isset($aresult[1])) {
218 2
                    self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
219 2
                }
220
                // See https://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx
221
                // Might be 11, anyway !
222 2
                if (stripos(self::$userAgentString, 'trident') !== false) {
223 2
                    preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches);
224 2
                    if (isset($matches[1])) {
225 1
                        self::$browser->setVersion($matches[1]);
226 1
                    }
227
228
                    // At this poing in the method, we know the MSIE and Trident
229
                    // strings are present in the $userAgentString. If we're in
230
                    // compatibility mode, we need to determine the true version.
231
                    // If the MSIE version is 7.0, we can look at the Trident
232
                    // version to *approximate* the true IE version. If we don't
233
                    // find a matching pair, ( e.g. MSIE 7.0 && Trident/7.0 )
234
                    // we're *not* in compatibility mode and the browser really
235
                    // is version 7.0.
236 2
                    if (stripos(self::$userAgentString, 'MSIE 7.0;')) {
237 1
                        if (stripos(self::$userAgentString, 'Trident/7.0;')) {
238
                            // IE11 in compatibility mode
239 1
                            self::$browser->setVersion('11.0');
240 1
                            self::$browser->setIsCompatibilityMode(true);
241 1
                        } elseif (stripos(self::$userAgentString, 'Trident/6.0;')) {
242
                            // IE10 in compatibility mode
243 1
                            self::$browser->setVersion('10.0');
244 1
                            self::$browser->setIsCompatibilityMode(true);
245 1
                        } elseif (stripos(self::$userAgentString, 'Trident/5.0;')) {
246
                            // IE9 in compatibility mode
247 1
                            self::$browser->setVersion('9.0');
248 1
                            self::$browser->setIsCompatibilityMode(true);
249 1
                        } elseif (stripos(self::$userAgentString, 'Trident/4.0;')) {
250
                            // IE8 in compatibility mode
251 1
                            self::$browser->setVersion('8.0');
252 1
                            self::$browser->setIsCompatibilityMode(true);
253 1
                        }
254 1
                    }
255 2
                }
256
257 2
                return true;
258
            } // Test for versions >= 11
259
            else {
260 8
                if (stripos(self::$userAgentString, 'trident') !== false) {
261 1
                    self::$browser->setName(Browser::IE);
262
263 1
                    preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches);
264 1
                    if (isset($matches[1])) {
265 1
                        self::$browser->setVersion($matches[1]);
266
267 1
                        return true;
268
                    } else {
269
                        return false;
270
                    }
271
                } // Test for Pocket IE
272
                else {
273 7
                    if (stripos(self::$userAgentString, 'mspie') !== false ||
274 7
                        stripos(
275 7
                            self::$userAgentString,
276
                            'pocket'
277 7
                        ) !== false
278 7
                    ) {
279
                        $aresult = explode(' ', stristr(self::$userAgentString, 'mspie'));
280
                        self::$browser->setName(Browser::POCKET_IE);
281
282
                        if (stripos(self::$userAgentString, 'mspie') !== false) {
283
                            if (isset($aresult[1])) {
284
                                self::$browser->setVersion($aresult[1]);
285
                            }
286
                        } else {
287
                            $aversion = explode('/', self::$userAgentString);
288
                            if (isset($aversion[1])) {
289
                                self::$browser->setVersion($aversion[1]);
290
                            }
291
                        }
292
293
                        return true;
294
                    }
295
                }
296
            }
297
        }
298
299 7
        return false;
300
    }
301
302
    /**
303
     * Determine if the browser is Opera.
304
     *
305
     * @return bool
306
     */
307 7
    public static function checkBrowserOpera()
308
    {
309 7
        if (stripos(self::$userAgentString, 'opera mini') !== false) {
310
            $resultant = stristr(self::$userAgentString, 'opera mini');
311
            if (preg_match('/\//', $resultant)) {
312
                $aresult = explode('/', $resultant);
313
                if (isset($aresult[1])) {
314
                    $aversion = explode(' ', $aresult[1]);
315
                    self::$browser->setVersion($aversion[0]);
316
                }
317
            } else {
318
                $aversion = explode(' ', stristr($resultant, 'opera mini'));
319
                if (isset($aversion[1])) {
320
                    self::$browser->setVersion($aversion[1]);
321
                }
322
            }
323
            self::$browser->setName(Browser::OPERA_MINI);
324
325
            return true;
326 7
        } elseif (stripos(self::$userAgentString, 'OPiOS') !== false) {
327 1
            $aresult = explode('/', stristr(self::$userAgentString, 'OPiOS'));
328 1
            if (isset($aresult[1])) {
329 1
                $aversion = explode(' ', $aresult[1]);
330 1
                self::$browser->setVersion($aversion[0]);
331 1
            }
332 1
            self::$browser->setName(Browser::OPERA_MINI);
333
334 1
            return true;
335 7
        } elseif (stripos(self::$userAgentString, 'opera') !== false) {
336 1
            $resultant = stristr(self::$userAgentString, 'opera');
337 1
            if (preg_match('/Version\/(1[0-2].*)$/', $resultant, $matches)) {
338 1
                if (isset($matches[1])) {
339 1
                    self::$browser->setVersion($matches[1]);
340 1
                }
341 1
            } elseif (preg_match('/\//', $resultant)) {
342
                $aresult = explode('/', str_replace('(', ' ', $resultant));
343
                if (isset($aresult[1])) {
344
                    $aversion = explode(' ', $aresult[1]);
345
                    self::$browser->setVersion($aversion[0]);
346
                }
347
            } else {
348 1
                $aversion = explode(' ', stristr($resultant, 'opera'));
349 1
                self::$browser->setVersion(isset($aversion[1]) ? $aversion[1] : '');
350
            }
351 1
            self::$browser->setName(Browser::OPERA);
352
353 1
            return true;
354 6
        } elseif (stripos(self::$userAgentString, ' OPR/') !== false) {
355 1
            self::$browser->setName(Browser::OPERA);
356 1
            if (preg_match('/OPR\/([\d\.]*)/', self::$userAgentString, $matches)) {
357 1
                if (isset($matches[1])) {
358 1
                    self::$browser->setVersion($matches[1]);
359 1
                }
360 1
            }
361
362 1
            return true;
363
        }
364
365 6
        return false;
366
    }
367
368
    /**
369
     * Determine if the browser is Chrome.
370
     *
371
     * @return bool
372
     */
373 4 View Code Duplication
    public static function checkBrowserChrome()
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...
374
    {
375 4
        if (stripos(self::$userAgentString, 'Chrome') !== false) {
376 2
            $aresult = explode('/', stristr(self::$userAgentString, 'Chrome'));
377 2
            if (isset($aresult[1])) {
378 2
                $aversion = explode(' ', $aresult[1]);
379 2
                self::$browser->setVersion($aversion[0]);
380 2
            }
381 2
            self::$browser->setName(Browser::CHROME);
382
383 2
            return true;
384 3
        } elseif (stripos(self::$userAgentString, 'CriOS') !== false) {
385 1
            $aresult = explode('/', stristr(self::$userAgentString, 'CriOS'));
386 1
            if (isset($aresult[1])) {
387 1
                $aversion = explode(' ', $aresult[1]);
388 1
                self::$browser->setVersion($aversion[0]);
389 1
            }
390 1
            self::$browser->setName(Browser::CHROME);
391
392 1
            return true;
393
        }
394
395 3
        return false;
396
    }
397
398
    /**
399
     * Determine if the browser is Vivaldi.
400
     *
401
     * @return bool
402
     */
403 6 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...
404
    {
405 6
        if (stripos(self::$userAgentString, 'Vivaldi') !== false) {
406 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Vivaldi'));
407 1
            if (isset($aresult[1])) {
408 1
                $aversion = explode(' ', $aresult[1]);
409 1
                self::$browser->setVersion($aversion[0]);
410 1
            }
411 1
            self::$browser->setName(Browser::VIVALDI);
412
413 1
            return true;
414
        }
415
416 6
        return false;
417
    }
418
419
    /**
420
     * Determine if the browser is Microsoft Edge.
421
     *
422
     * @return bool
423
     */
424 7
    public static function checkBrowserEdge()
425
    {
426 7
        if (stripos(self::$userAgentString, 'Edge') !== false) {
427 1
            $version = explode('Edge/', self::$userAgentString);
428 1
            if (isset($version[1])) {
429 1
                self::$browser->setVersion((float)$version[1]);
430 1
            }
431 1
            self::$browser->setName(Browser::EDGE);
432
433 1
            return true;
434
        }
435
436 7
        return false;
437
    }
438
439
    /**
440
     * Determine if the browser is Google Search Appliance.
441
     *
442
     * @return bool
443
     */
444 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...
445
    {
446 2
        if (stripos(self::$userAgentString, 'GSA') !== false) {
447
            $aresult = explode('/', stristr(self::$userAgentString, 'GSA'));
448
            if (isset($aresult[1])) {
449
                $aversion = explode(' ', $aresult[1]);
450
                self::$browser->setVersion($aversion[0]);
451
            }
452
            self::$browser->setName(Browser::GSA);
453
454
            return true;
455
        }
456
457 2
        return false;
458
    }
459
460
    /**
461
     * Determine if the browser is WebTv.
462
     *
463
     * @return bool
464
     */
465 8 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...
466
    {
467 8
        if (stripos(self::$userAgentString, 'webtv') !== false) {
468
            $aresult = explode('/', stristr(self::$userAgentString, 'webtv'));
469
            if (isset($aresult[1])) {
470
                $aversion = explode(' ', $aresult[1]);
471
                self::$browser->setVersion($aversion[0]);
472
            }
473
            self::$browser->setName(Browser::WEBTV);
474
475
            return true;
476
        }
477
478 8
        return false;
479
    }
480
481
    /**
482
     * Determine if the browser is NetPositive.
483
     *
484
     * @return bool
485
     */
486 1
    public static function checkBrowserNetPositive()
487
    {
488 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...
489
            $aresult = explode('/', stristr(self::$userAgentString, 'NetPositive'));
490
            if (isset($aresult[1])) {
491
                $aversion = explode(' ', $aresult[1]);
492
                self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
493
            }
494
            self::$browser->setName(Browser::NETPOSITIVE);
495
496
            return true;
497
        }
498
499 1
        return false;
500
    }
501
502
    /**
503
     * Determine if the browser is Galeon.
504
     *
505
     * @return bool
506
     */
507 6 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...
508
    {
509 6
        if (stripos(self::$userAgentString, 'galeon') !== false) {
510
            $aresult = explode(' ', stristr(self::$userAgentString, 'galeon'));
511
            $aversion = explode('/', $aresult[0]);
512
            if (isset($aversion[1])) {
513
                self::$browser->setVersion($aversion[1]);
514
            }
515
            self::$browser->setName(Browser::GALEON);
516
517
            return true;
518
        }
519
520 6
        return false;
521
    }
522
523
    /**
524
     * Determine if the browser is Konqueror.
525
     *
526
     * @return bool
527
     */
528 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...
529
    {
530 1
        if (stripos(self::$userAgentString, 'Konqueror') !== false) {
531
            $aresult = explode(' ', stristr(self::$userAgentString, 'Konqueror'));
532
            $aversion = explode('/', $aresult[0]);
533
            if (isset($aversion[1])) {
534
                self::$browser->setVersion($aversion[1]);
535
            }
536
            self::$browser->setName(Browser::KONQUEROR);
537
538
            return true;
539
        }
540
541 1
        return false;
542
    }
543
544
    /**
545
     * Determine if the browser is iCab.
546
     *
547
     * @return bool
548
     */
549 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...
550
    {
551 1
        if (stripos(self::$userAgentString, 'icab') !== false) {
552
            $aversion = explode(' ', stristr(str_replace('/', ' ', self::$userAgentString), 'icab'));
553
            if (isset($aversion[1])) {
554
                self::$browser->setVersion($aversion[1]);
555
            }
556
            self::$browser->setName(Browser::ICAB);
557
558
            return true;
559
        }
560
561 1
        return false;
562
    }
563
564
    /**
565
     * Determine if the browser is OmniWeb.
566
     *
567
     * @return bool
568
     */
569 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...
570
    {
571 3
        if (stripos(self::$userAgentString, 'omniweb') !== false) {
572
            $aresult = explode('/', stristr(self::$userAgentString, 'omniweb'));
573
            $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : '');
574
            self::$browser->setVersion($aversion[0]);
575
            self::$browser->setName(Browser::OMNIWEB);
576
577
            return true;
578
        }
579
580 3
        return false;
581
    }
582
583
    /**
584
     * Determine if the browser is Phoenix.
585
     *
586
     * @return bool
587
     */
588 1
    public static function checkBrowserPhoenix()
589
    {
590 1
        if (stripos(self::$userAgentString, 'Phoenix') !== false) {
591
            $aversion = explode('/', stristr(self::$userAgentString, 'Phoenix'));
592
            if (isset($aversion[1])) {
593
                self::$browser->setVersion($aversion[1]);
594
            }
595
            self::$browser->setName(Browser::PHOENIX);
596
597
            return true;
598
        }
599
600 1
        return false;
601
    }
602
603
    /**
604
     * Determine if the browser is Firebird.
605
     *
606
     * @return bool
607
     */
608 1
    public static function checkBrowserFirebird()
609
    {
610 1
        if (stripos(self::$userAgentString, 'Firebird') !== false) {
611
            $aversion = explode('/', stristr(self::$userAgentString, 'Firebird'));
612
            if (isset($aversion[1])) {
613
                self::$browser->setVersion($aversion[1]);
614
            }
615
            self::$browser->setName(Browser::FIREBIRD);
616
617
            return true;
618
        }
619
620 1
        return false;
621
    }
622
623
    /**
624
     * Determine if the browser is Netscape Navigator 9+.
625
     *
626
     * @return bool
627
     */
628 6
    public static function checkBrowserNetscapeNavigator9Plus()
629
    {
630 6
        if (stripos(self::$userAgentString, 'Firefox') !== false &&
631 2
            preg_match('/Navigator\/([^ ]*)/i', self::$userAgentString, $matches)
632 6
        ) {
633
            if (isset($matches[1])) {
634
                self::$browser->setVersion($matches[1]);
635
            }
636
            self::$browser->setName(Browser::NETSCAPE_NAVIGATOR);
637
638
            return true;
639 6
        } elseif (stripos(self::$userAgentString, 'Firefox') === false &&
640 5
            preg_match('/Netscape6?\/([^ ]*)/i', self::$userAgentString, $matches)
641 6
        ) {
642
            if (isset($matches[1])) {
643
                self::$browser->setVersion($matches[1]);
644
            }
645
            self::$browser->setName(Browser::NETSCAPE_NAVIGATOR);
646
647
            return true;
648
        }
649
650 6
        return false;
651
    }
652
653
    /**
654
     * Determine if the browser is Shiretoko.
655
     *
656
     * @return bool
657
     */
658 1
    public static function checkBrowserShiretoko()
659
    {
660 1
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
661
            preg_match('/Shiretoko\/([^ ]*)/i', self::$userAgentString, $matches)
662 1
        ) {
663
            if (isset($matches[1])) {
664
                self::$browser->setVersion($matches[1]);
665
            }
666
            self::$browser->setName(Browser::SHIRETOKO);
667
668
            return true;
669
        }
670
671 1
        return false;
672
    }
673
674
    /**
675
     * Determine if the browser is Ice Cat.
676
     *
677
     * @return bool
678
     */
679 1
    public static function checkBrowserIceCat()
680
    {
681 1
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
682
            preg_match('/IceCat\/([^ ]*)/i', self::$userAgentString, $matches)
683 1
        ) {
684
            if (isset($matches[1])) {
685
                self::$browser->setVersion($matches[1]);
686
            }
687
            self::$browser->setName(Browser::ICECAT);
688
689
            return true;
690
        }
691
692 1
        return false;
693
    }
694
695
    /**
696
     * Determine if the browser is Nokia.
697
     *
698
     * @return bool
699
     */
700 2
    public static function checkBrowserNokia()
701
    {
702 2
        if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", self::$userAgentString, $matches)) {
703
            self::$browser->setVersion($matches[2]);
704
            if (stripos(self::$userAgentString, 'Series60') !== false ||
705
                strpos(self::$userAgentString, 'S60') !== false
706
            ) {
707
                self::$browser->setName(Browser::NOKIA_S60);
708
            } else {
709
                self::$browser->setName(Browser::NOKIA);
710
            }
711
712
            return true;
713
        }
714
715 2
        return false;
716
    }
717
718
    /**
719
     * Determine if the browser is Firefox.
720
     *
721
     * @return bool
722
     */
723 5 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...
724
    {
725 5
        if (stripos(self::$userAgentString, 'safari') === false) {
726 4
            if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) {
727 2
                if (isset($matches[1])) {
728 2
                    self::$browser->setVersion($matches[1]);
729 2
                }
730 2
                self::$browser->setName(Browser::FIREFOX);
731
732 2
                return true;
733 2
            } elseif (preg_match('/Firefox$/i', self::$userAgentString, $matches)) {
734
                self::$browser->setVersion('');
735
                self::$browser->setName(Browser::FIREFOX);
736
737
                return true;
738
            }
739 2
        }
740
741 4
        return false;
742
    }
743
744
    /**
745
     * Determine if the browser is SeaMonkey.
746
     *
747
     * @return bool
748
     */
749 6 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...
750
    {
751 6
        if (stripos(self::$userAgentString, 'safari') === false) {
752 5
            if (preg_match("/SeaMonkey[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) {
753 1
                if (isset($matches[1])) {
754 1
                    self::$browser->setVersion($matches[1]);
755 1
                }
756 1
                self::$browser->setName(Browser::SEAMONKEY);
757
758 1
                return true;
759 4
            } elseif (preg_match('/SeaMonkey$/i', self::$userAgentString, $matches)) {
760
                self::$browser->setVersion('');
761
                self::$browser->setName(Browser::SEAMONKEY);
762
763
                return true;
764
            }
765 4
        }
766
767 5
        return false;
768
    }
769
770
    /**
771
     * Determine if the browser is Iceweasel.
772
     *
773
     * @return bool
774
     */
775 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...
776
    {
777 1
        if (stripos(self::$userAgentString, 'Iceweasel') !== false) {
778
            $aresult = explode('/', stristr(self::$userAgentString, 'Iceweasel'));
779
            if (isset($aresult[1])) {
780
                $aversion = explode(' ', $aresult[1]);
781
                self::$browser->setVersion($aversion[0]);
782
            }
783
            self::$browser->setName(Browser::ICEWEASEL);
784
785
            return true;
786
        }
787
788 1
        return false;
789
    }
790
791
    /**
792
     * Determine if the browser is Mozilla.
793
     *
794
     * @return bool
795
     */
796 1
    public static function checkBrowserMozilla()
797
    {
798 1
        if (stripos(self::$userAgentString, 'mozilla') !== false &&
799 1
            preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString) &&
800
            stripos(self::$userAgentString, 'netscape') === false
801 1
        ) {
802
            $aversion = explode(' ', stristr(self::$userAgentString, 'rv:'));
803
            preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString, $aversion);
804
            self::$browser->setVersion(str_replace('rv:', '', $aversion[0]));
805
            self::$browser->setName(Browser::MOZILLA);
806
807
            return true;
808 1
        } elseif (stripos(self::$userAgentString, 'mozilla') !== false &&
809 1
            preg_match('/rv:[0-9]\.[0-9]/i', self::$userAgentString) &&
810
            stripos(self::$userAgentString, 'netscape') === false
811 1
        ) {
812
            $aversion = explode('', stristr(self::$userAgentString, 'rv:'));
813
            self::$browser->setVersion(str_replace('rv:', '', $aversion[0]));
814
            self::$browser->setName(Browser::MOZILLA);
815
816
            return true;
817 1
        } elseif (stripos(self::$userAgentString, 'mozilla') !== false &&
818 1
            preg_match('/mozilla\/([^ ]*)/i', self::$userAgentString, $matches) &&
819
            stripos(self::$userAgentString, 'netscape') === false
820 1
        ) {
821
            if (isset($matches[1])) {
822
                self::$browser->setVersion($matches[1]);
823
            }
824
            self::$browser->setName(Browser::MOZILLA);
825
826
            return true;
827
        }
828
829 1
        return false;
830
    }
831
832
    /**
833
     * Determine if the browser is Lynx.
834
     *
835
     * @return bool
836
     */
837 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...
838
    {
839 1
        if (stripos(self::$userAgentString, 'lynx') !== false) {
840
            $aresult = explode('/', stristr(self::$userAgentString, 'Lynx'));
841
            $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ''));
842
            self::$browser->setVersion($aversion[0]);
843
            self::$browser->setName(Browser::LYNX);
844
845
            return true;
846
        }
847
848 1
        return false;
849
    }
850
851
    /**
852
     * Determine if the browser is Amaya.
853
     *
854
     * @return bool
855
     */
856 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...
857
    {
858 1
        if (stripos(self::$userAgentString, 'amaya') !== false) {
859
            $aresult = explode('/', stristr(self::$userAgentString, 'Amaya'));
860
            if (isset($aresult[1])) {
861
                $aversion = explode(' ', $aresult[1]);
862
                self::$browser->setVersion($aversion[0]);
863
            }
864
            self::$browser->setName(Browser::AMAYA);
865
866
            return true;
867
        }
868
869 1
        return false;
870
    }
871
872
    /**
873
     * Determine if the browser is Safari.
874
     *
875
     * @return bool
876
     */
877 2
    public static function checkBrowserSafari()
878
    {
879 2
        if (stripos(self::$userAgentString, 'Safari') !== false) {
880 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Version'));
881 1
            if (isset($aresult[1])) {
882 1
                $aversion = explode(' ', $aresult[1]);
883 1
                self::$browser->setVersion($aversion[0]);
884 1
            } else {
885
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
886
            }
887 1
            self::$browser->setName(Browser::SAFARI);
888
889 1
            return true;
890
        }
891
892 1
        return false;
893
    }
894
895
    /**
896
     * Determine if the browser is Yandex.
897
     *
898
     * @return bool
899
     */
900 4 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...
901
    {
902 4
        if (stripos(self::$userAgentString, 'YaBrowser') !== false) {
903 1
            $aresult = explode('/', stristr(self::$userAgentString, 'YaBrowser'));
904 1
            if (isset($aresult[1])) {
905 1
                $aversion = explode(' ', $aresult[1]);
906 1
                self::$browser->setVersion($aversion[0]);
907 1
            }
908 1
            self::$browser->setName(Browser::YANDEX);
909
910 1
            return true;
911
        }
912
913 4
        return false;
914
    }
915
    
916
    /**
917
     * Determine if the browser is Comodo Dragon / Ice Dragon / Chromodo.
918
     *
919
     * @return bool
920
     */
921 6 View Code Duplication
    public static function checkBrowserDragon()
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...
922
    {
923 6
        if (stripos(self::$userAgentString, 'Dragon') !== false) {
924 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Dragon'));
925 1
            if (isset($aresult[1])) {
926 1
                $aversion = explode(' ', $aresult[1]);
927 1
                self::$browser->setVersion($aversion[0]);
928 1
            }
929 1
            self::$browser->setName(Browser::DRAGON);
930
931 1
            return true;
932
        }
933
934 6
        return false;
935
    }
936
937
    /**
938
     * Determine if the browser is Android.
939
     *
940
     * @return bool
941
     */
942 3
    public static function checkBrowserAndroid()
943
    {
944
        // Navigator
945 3
        if (stripos(self::$userAgentString, 'Android') !== false) {
946
            if (preg_match('/Version\/([\d\.]*)/i', self::$userAgentString, $matches)) {
947
                if (isset($matches[1])) {
948
                    self::$browser->setVersion($matches[1]);
949
                }
950
            } else {
951
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
952
            }
953
            self::$browser->setName(Browser::NAVIGATOR);
954
955
            return true;
956
        }
957
958 3
        return false;
959
    }
960
}
961