Completed
Push — master ( 7e3ce6...84d414 )
by Gabriel
02:44
created

BrowserDetector::checkBrowserOpera()   C

Complexity

Conditions 16
Paths 15

Size

Total Lines 60
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 32.384

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 60
ccs 30
cts 50
cp 0.6
rs 6.2854
cc 16
eloc 43
nc 15
nop 0
crap 32.384

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