Test Failed
Pull Request — master (#78)
by Gabriel
03:36
created

BrowserDetector::checkBrowserNSPlayer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 16
loc 16
ccs 0
cts 0
cp 0
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
crap 12
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
    protected static $edgeVersionsMap = null;
11
12
    /**
13
     * @var Browser
14
     */
15
    protected static $browser;
16
17
    protected static $browsersList = array(
18
        // well-known, well-used
19
        // Special Notes:
20
        // (1) Opera must be checked before FireFox due to the odd
21
        //     user agents used in some older versions of Opera
22
        // (2) WebTV is strapped onto Internet Explorer so we must
23
        //     check for WebTV before IE
24
        // (3) Because of Internet Explorer 11 using
25
        //     "Mozilla/5.0 ([...] Trident/7.0; rv:11.0) like Gecko"
26
        //     as user agent, tests for IE must be run before any
27
        //     tests checking for "Mozilla"
28
        // (4) (deprecated) Galeon is based on Firefox and needs to be
29
        //     tested before Firefox is tested
30
        // (5) OmniWeb is based on Safari so OmniWeb check must occur
31
        //     before Safari
32
        // (6) Netscape 9+ is based on Firefox so Netscape checks
33
        //     before FireFox are necessary
34
        // (7) Microsoft Edge must be checked before Chrome and Safari
35
        // (7) Vivaldi must be checked before Chrome
36
        'WebTv',
37
        'InternetExplorer',
38
        'Edge',
39
        'Opera',
40
        'Vivaldi',
41
        'Dragon',
42
        'Galeon',
43
        'NetscapeNavigator9Plus',
44
        'SeaMonkey',
45
        'Firefox',
46
        'Yandex',
47
        'Samsung',
48
        'Chrome',
49
        'OmniWeb',
50
        'UCBrowser', //before Android
51
        // common mobile
52
        'Android',
53
        'BlackBerry',
54
        'Nokia',
55
        'Gsa',
56
        // WebKit base check (post mobile and others)
57
        'AppleNews',
58
        'Safari',
59
        // everyone else
60
        'NetPositive',
61
        'Firebird',
62
        'Konqueror',
63
        'Icab',
64
        'Phoenix',
65
        'Amaya',
66
        'Lynx',
67
        'NSPlayer',
68
        'Office',
69
        'Shiretoko',
70
        'IceCat',
71
        'Iceweasel',
72
        'Mozilla', /* Mozilla is such an open standard that you must check it last */
73
    );
74
75
    /**
76
     * @return array
77
     */
78
    public static function getEdgeVersionsMap()
79
    {
80
        if (self::$edgeVersionsMap) return self::$edgeVersionsMap;
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

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