Passed
Branch develop (283cae)
by Gabriel
05:29
created

BrowserDetector::checkChromeFrame()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

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