Completed
Push — master ( 5db01c...94622e )
by Gabriel
02:28
created

BrowserDetector::checkBrowserGaleon()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 6.087

Importance

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