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

BrowserDetector::checkBrowserUCBrowser()   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
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
175
    /**
176
     * Determine if the user is using a BlackBerry.
177
     *
178
     * @return bool
179
     */
180
    public static function checkBrowserBlackBerry()
181 2
    {
182
        if (stripos(self::$userAgentString, 'blackberry') !== false) {
183 2
            if (stripos(self::$userAgentString, 'Version/') !== false) {
184 2
                $aresult = explode('Version/', self::$userAgentString);
185 2
                if (isset($aresult[1])) {
186 2
                    $aversion = explode(' ', $aresult[1]);
187
                    self::$browser->setVersion($aversion[0]);
188
                }
189
            } else {
190
                $aresult = explode('/', stristr(self::$userAgentString, 'BlackBerry'));
191
                if (isset($aresult[1])) {
192 2
                    $aversion = explode(' ', $aresult[1]);
193
                    self::$browser->setVersion($aversion[0]);
194
                }
195
            }
196
            self::$browser->setName(Browser::BLACKBERRY);
197
198
            return true;
199
        } elseif (stripos(self::$userAgentString, 'BB10') !== false) {
200 8
            $aresult = explode('Version/10.', self::$userAgentString);
201
            if (isset($aresult[1])) {
202
                $aversion = explode(' ', $aresult[1]);
203 8
                self::$browser->setVersion('10.' . $aversion[0]);
204
            }
205
            self::$browser->setName(Browser::BLACKBERRY);
206
            return true;
207
        }
208
209
        return false;
210
    }
211
212
    /**
213
     * Determine if the browser is Internet Explorer.
214 8
     *
215 8
     * @return bool
216
     */
217 2
    public static function checkBrowserInternetExplorer()
218
    {
219
        // Test for v1 - v1.5 IE
220
        if (stripos(self::$userAgentString, 'microsoft internet explorer') !== false) {
221
            self::$browser->setName(Browser::IE);
222
            self::$browser->setVersion('1.0');
223
            $aresult = stristr(self::$userAgentString, '/');
224
            if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
225
                self::$browser->setVersion('1.5');
226 2
            }
227 2
228 2
            return true;
229 2
        } // Test for versions > 1.5 and < 11 and some cases of 11
230 2
        else {
231
            if (stripos(self::$userAgentString, 'msie') !== false && stripos(self::$userAgentString, 'opera') === false
232
            ) {
233 2
                // See if the browser is the odd MSN Explorer
234 2 View Code Duplication
                if (stripos(self::$userAgentString, 'msnb') !== false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

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