Test Failed
Pull Request — master (#78)
by Gabriel
02:37
created

BrowserDetector::checkWebkit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
949 1
    {
950 1
        if (stripos(self::$userAgentString, 'YaBrowser') !== false) {
951 1
            $aresult = explode('/', stristr(self::$userAgentString, 'YaBrowser'));
952 1
            if (isset($aresult[1])) {
953 1
                $aversion = explode(' ', $aresult[1]);
954 1
                self::$browser->setVersion($aversion[0]);
955
            }
956 1
            self::$browser->setName(Browser::YANDEX);
957
958
            return true;
959 4
        }
960
961
        return false;
962
    }
963
    
964
    /**
965
     * Determine if the browser is Comodo Dragon / Ice Dragon / Chromodo.
966
     *
967 6
     * @return bool
968
     */
969 6 View Code Duplication
    public static function checkBrowserDragon()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
970 1
    {
971 1
        if (stripos(self::$userAgentString, 'Dragon') !== false) {
972 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Dragon'));
973 1
            if (isset($aresult[1])) {
974 1
                $aversion = explode(' ', $aresult[1]);
975 1
                self::$browser->setVersion($aversion[0]);
976
            }
977 1
            self::$browser->setName(Browser::DRAGON);
978
979
            return true;
980 6
        }
981
982
        return false;
983
    }
984
985
    /**
986
     * Determine if the browser is Android.
987
     *
988 3
     * @return bool
989
     */
990
    public static function checkBrowserAndroid()
991 3
    {
992
        // Android Navigator
993 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...
994
            if (preg_match('/Version\/([\d\.]*)/i', self::$userAgentString, $matches)) {
995
                if (isset($matches[1])) {
996
                    self::$browser->setVersion($matches[1]);
997
                }
998
            } else {
999
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
1000
            }
1001
            self::$browser->setName(Browser::NAVIGATOR);
1002
1003
            return true;
1004 3
        }
1005
1006
        // Dalvik (Android OS)
1007
        if (stripos(self::$userAgentString, 'Dalvik/') !== false) {
1008
            $aresult = explode('/', stristr(self::$userAgentString, 'Dalvik'));
1009
            if (isset($aresult[1])) {
1010
                $aversion = explode(' ', $aresult[1]);
1011
                self::$browser->setVersion($aversion[0]);
1012
            }
1013
            self::$browser->setName(Browser::DALVIK);
1014
1015
            return true;
1016
        }
1017
1018
        return false;
1019
    }
1020
1021
    /**
1022
     * Determine if the browser is UCBrowser.
1023
     *
1024
     * @return bool
1025
     */
1026 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...
1027
    {
1028
        // Navigator
1029
        if (stripos(self::$userAgentString, 'UCBrowser/') !== false) {
1030
            $aresult = explode('/', stristr(self::$userAgentString, 'UCBrowser'));
1031
            if (isset($aresult[1])) {
1032
                $aversion = explode(' ', $aresult[1]);
1033
                self::$browser->setVersion($aversion[0]);
1034
            }
1035
            self::$browser->setName(Browser::UCBROWSER);
1036
1037
            return true;
1038
        }
1039
1040
        return false;
1041
    }
1042
1043
    /**
1044
     * Determine if the browser is Windows Media Player.
1045
     *
1046
     * @return bool
1047
     */
1048 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...
1049
    {
1050
        // Navigator
1051
        if (stripos(self::$userAgentString, 'NSPlayer/') !== false) {
1052
            $aresult = explode('/', stristr(self::$userAgentString, 'NSPlayer'));
1053
            if (isset($aresult[1])) {
1054
                $aversion = explode(' ', $aresult[1]);
1055
                self::$browser->setVersion($aversion[0]);
1056
            }
1057
            self::$browser->setName(Browser::NSPLAYER);
1058
1059
            return true;
1060
        }
1061
1062
        return false;
1063
    }
1064
1065
    /**
1066
     * Determine if the browser is Microsoft Office.
1067
     *
1068
     * @return bool
1069
     */
1070
    public static function checkBrowserOffice()
1071
    {
1072
        // Navigator
1073
        if (stripos(self::$userAgentString, 'Microsoft Office') !== false) {
1074
            self::$browser->setVersion(Browser::VERSION_UNKNOWN);
1075
            self::$browser->setName(Browser::NSPLAYER);
1076
1077
            return true;
1078
        }
1079
1080
        return false;
1081
    }
1082
1083
    /**
1084
     * Determine if the browser is the Apple News app.
1085
     *
1086
     * @return bool
1087
     */
1088
    public static function checkBrowserAppleNews()
1089
    {
1090
        // Navigator
1091 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...
1092
            if (preg_match('/Version\/([\d\.]*)/i', self::$userAgentString, $matches)) {
1093
                if (isset($matches[1])) {
1094
                    self::$browser->setVersion($matches[1]);
1095
                }
1096
            } else {
1097
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
1098
            }
1099
            self::$browser->setName(Browser::APPLE_NEWS);
1100
1101
            return true;
1102
        }
1103
1104
        return false;
1105
    }
1106
}
1107