Completed
Push — master ( 691ca8...ff4678 )
by Gabriel
05:04
created

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