Completed
Push — master ( b686a6...8f2f13 )
by Gabriel
04:01
created

BrowserDetector::checkBrowserBlackBerry()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 7

Importance

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