Completed
Push — master ( 8f2f13...bf6127 )
by Gabriel
07:49
created

BrowserDetector::checkBrowserMozilla()   C

Complexity

Conditions 11
Paths 5

Size

Total Lines 35
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 38.0748

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 35
ccs 11
cts 28
cp 0.3929
rs 5.2653
cc 11
eloc 24
nc 5
nop 0
crap 38.0748

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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