Completed
Pull Request — master (#61)
by
unknown
03:34
created

BrowserDetector::checkBrowserGsa()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 6.087

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 15
loc 15
ccs 3
cts 10
cp 0.3
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
crap 6.087
1
<?php
2
3
namespace Sinergi\BrowserDetector;
4
5
class BrowserDetector implements DetectorInterface
6
{
7
    const FUNC_PREFIX = 'checkBrowser';
8
9
    protected static $userAgentString;
10
11
    /**
12
     * @var Browser
13
     */
14
    protected static $browser;
15
16
    protected static $browsersList = array(
17
        // well-known, well-used
18
        // Special Notes:
19
        // (1) Opera must be checked before FireFox due to the odd
20
        //     user agents used in some older versions of Opera
21
        // (2) WebTV is strapped onto Internet Explorer so we must
22
        //     check for WebTV before IE
23
        // (3) Because of Internet Explorer 11 using
24
        //     "Mozilla/5.0 ([...] Trident/7.0; rv:11.0) like Gecko"
25
        //     as user agent, tests for IE must be run before any
26
        //     tests checking for "Mozilla"
27
        // (4) (deprecated) Galeon is based on Firefox and needs to be
28
        //     tested before Firefox is tested
29
        // (5) OmniWeb is based on Safari so OmniWeb check must occur
30
        //     before Safari
31
        // (6) Netscape 9+ is based on Firefox so Netscape checks
32
        //     before FireFox are necessary
33
        // (7) Microsoft Edge must be checked before Chrome and Safari
34
        // (7) Vivaldi must be checked before Chrome
35
        'WebTv',
36
        'InternetExplorer',
37
        'Edge',
38
        'Opera',
39
        'Vivaldi',
40
        'Galeon',
41
        'NetscapeNavigator9Plus',
42
        'SeaMonkey',
43
        'Firefox',
44
        'Yandex',
45
        'Chrome',
46
        'OmniWeb',
47
        // common mobile
48
        'Android',
49
        'BlackBerry',
50
        'Nokia',
51
        'Gsa',
52
        // common bots
53
        'Robot',
54
        // WebKit base check (post mobile and others)
55
        'Safari',
56
        // everyone else
57
        'NetPositive',
58
        'Firebird',
59
        'Konqueror',
60
        'Icab',
61
        'Phoenix',
62
        'Amaya',
63
        'Lynx',
64
        'Shiretoko',
65
        'IceCat',
66
        'Iceweasel',
67
        'Mozilla', /* Mozilla is such an open standard that you must check it last */
68
    );
69
70
    /**
71
     * Routine to determine the browser type.
72
     *
73
     * @param Browser $browser
74
     * @param UserAgent $userAgent
75
     *
76
     * @return bool
77
     */
78 7
    public static function detect(Browser $browser, UserAgent $userAgent = null)
79
    {
80 7
        self::$browser = $browser;
81 7
        if (is_null($userAgent)) {
82
            $userAgent = self::$browser->getUserAgent();
83
        }
84 7
        self::$userAgentString = $userAgent->getUserAgentString();
85
86 7
        self::$browser->setName(Browser::UNKNOWN);
87 7
        self::$browser->setVersion(Browser::VERSION_UNKNOWN);
88
89 7
        self::checkChromeFrame();
90
91 7
        foreach (self::$browsersList as $browserName) {
92 7
            $funcName = self::FUNC_PREFIX . $browserName;
93
94 7
            if (self::$funcName()) {
95 6
                return true;
96
            }
97 7
        }
98
99 1
        return false;
100
    }
101
102
    /**
103
     * Determine if the user is using Chrome Frame.
104
     *
105
     * @return bool
106
     */
107 7
    public static function checkChromeFrame()
108
    {
109 7
        if (strpos(self::$userAgentString, 'chromeframe') !== false) {
110
            self::$browser->setIsChromeFrame(true);
111
112
            return true;
113
        }
114
115 7
        return false;
116
    }
117
118
    /**
119
     * Determine if the user is using a BlackBerry.
120
     *
121
     * @return bool
122
     */
123 3 View Code Duplication
    public static function checkBrowserBlackBerry()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
124
    {
125 3
        if (stripos(self::$userAgentString, 'blackberry') !== false) {
126 1
            $aresult = explode('/', stristr(self::$userAgentString, 'BlackBerry'));
127 1
            if (isset($aresult[1])) {
128 1
                $aversion = explode(' ', $aresult[1]);
129 1
                self::$browser->setVersion($aversion[0]);
130 1
            }
131 1
            self::$browser->setName(Browser::BLACKBERRY);
132
133 1
            return true;
134
        }
135
136 2
        return false;
137
    }
138
139
    /**
140
     * Determine if the browser is a robot.
141
     *
142
     * @return bool
143
     */
144 2
    public static function checkBrowserRobot()
145
    {
146 2
        if (stripos(self::$userAgentString, 'bot') !== false ||
147 2
            stripos(self::$userAgentString, 'spider') !== false ||
148 2
            stripos(self::$userAgentString, 'crawler') !== false
149 2
        ) {
150
            self::$browser->setIsRobot(true);
151
152
            return true;
153
        }
154
155 2
        return false;
156
    }
157
158
    /**
159
     * Determine if the browser is Internet Explorer.
160
     *
161
     * @return bool
162
     */
163 7
    public static function checkBrowserInternetExplorer()
164
    {
165
        // Test for v1 - v1.5 IE
166 7
        if (stripos(self::$userAgentString, 'microsoft internet explorer') !== false) {
167
            self::$browser->setName(Browser::IE);
168
            self::$browser->setVersion('1.0');
169
            $aresult = stristr(self::$userAgentString, '/');
170
            if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
171
                self::$browser->setVersion('1.5');
172
            }
173
174
            return true;
175
        } // Test for versions > 1.5 and < 11 and some cases of 11
176
        else {
177 7
            if (stripos(self::$userAgentString, 'msie') !== false && stripos(self::$userAgentString, 'opera') === false
178 7
            ) {
179
                // See if the browser is the odd MSN Explorer
180 2 View Code Duplication
                if (stripos(self::$userAgentString, 'msnb') !== false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
181
                    $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'MSN'));
182
                    self::$browser->setName(Browser::MSN);
183
                    if (isset($aresult[1])) {
184
                        self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
185
                    }
186
187
                    return true;
188
                }
189 2
                $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'msie'));
190 2
                self::$browser->setName(Browser::IE);
191 2
                if (isset($aresult[1])) {
192 2
                    self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
193 2
                }
194
                // See https://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx
195
                // Might be 11, anyway !
196 2
                if (stripos(self::$userAgentString, 'trident') !== false) {
197 2
                    preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches);
198 2
                    if (isset($matches[1])) {
199 1
                        self::$browser->setVersion($matches[1]);
200 1
                    }
201
202
                    // At this poing in the method, we know the MSIE and Trident
203
                    // strings are present in the $userAgentString. If we're in
204
                    // compatibility mode, we need to determine the true version.
205
                    // If the MSIE version is 7.0, we can look at the Trident
206
                    // version to *approximate* the true IE version. If we don't
207
                    // find a matching pair, ( e.g. MSIE 7.0 && Trident/7.0 )
208
                    // we're *not* in compatibility mode and the browser really
209
                    // is version 7.0.
210 2
                    if (stripos(self::$userAgentString, 'MSIE 7.0;'))
211 2
                    {
212
                      // IE11 in compatibility mode
213 1
                      if (stripos(self::$userAgentString, 'Trident/7.0;')) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 22
Loading history...
214 1
                          self::$browser->setVersion('11.0');
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
215 1
                          self::$browser->setIsCompatibilityMode(true);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
216 1
                      }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 22
Loading history...
217
                      // IE10 in compatibility mode
218 1
                      else if (stripos(self::$userAgentString, 'Trident/6.0;')) {
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 24 spaces, but found 22).
Loading history...
219 1
                          self::$browser->setVersion('10.0');
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
220 1
                          self::$browser->setIsCompatibilityMode(true);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
221 1
                      }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 22
Loading history...
222
                      // IE9 in compatibility mode
223 1
                      else if (stripos(self::$userAgentString, 'Trident/5.0;')) {
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 24 spaces, but found 22).
Loading history...
224 1
                          self::$browser->setVersion('9.0');
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
225 1
                          self::$browser->setIsCompatibilityMode(true);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
226 1
                      }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 22
Loading history...
227
                      // IE8 in compatibility mode
228 1
                      else if (stripos(self::$userAgentString, 'Trident/4.0;')) {
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 24 spaces, but found 22).
Loading history...
229 1
                          self::$browser->setVersion('8.0');
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
230 1
                          self::$browser->setIsCompatibilityMode(true);
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 28 spaces, but found 26).
Loading history...
231 1
                      }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 22
Loading history...
232 1
                    }
233
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
234 2
                }
235
236 2
                return true;
237
            } // Test for versions >= 11
238
            else {
239 7
                if (stripos(self::$userAgentString, 'trident') !== false) {
240 1
                    self::$browser->setName(Browser::IE);
241
242 1
                    preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches);
243 1
                    if (isset($matches[1])) {
244 1
                        self::$browser->setVersion($matches[1]);
245
246 1
                        return true;
247
                    } else {
248
                        return false;
249
                    }
250
                } // Test for Pocket IE
251
                else {
252 6
                    if (stripos(self::$userAgentString, 'mspie') !== false ||
253 6
                        stripos(
254 6
                            self::$userAgentString,
255
                            'pocket'
256 6
                        ) !== false
257 6
                    ) {
258
                        $aresult = explode(' ', stristr(self::$userAgentString, 'mspie'));
259
                        self::$browser->setName(Browser::POCKET_IE);
260
261
                        if (stripos(self::$userAgentString, 'mspie') !== false) {
262
                            if (isset($aresult[1])) {
263
                                self::$browser->setVersion($aresult[1]);
264
                            }
265
                        } else {
266
                            $aversion = explode('/', self::$userAgentString);
267
                            if (isset($aversion[1])) {
268
                                self::$browser->setVersion($aversion[1]);
269
                            }
270
                        }
271
272
                        return true;
273
                    }
274
                }
275
            }
276
        }
277
278 6
        return false;
279
    }
280
281
    /**
282
     * Determine if the browser is Opera.
283
     *
284
     * @return bool
285
     */
286 6
    public static function checkBrowserOpera()
287
    {
288 6
        if (stripos(self::$userAgentString, 'opera mini') !== false) {
289
            $resultant = stristr(self::$userAgentString, 'opera mini');
290
            if (preg_match('/\//', $resultant)) {
291
                $aresult = explode('/', $resultant);
292
                if (isset($aresult[1])) {
293
                    $aversion = explode(' ', $aresult[1]);
294
                    self::$browser->setVersion($aversion[0]);
295
                }
296
            } else {
297
                $aversion = explode(' ', stristr($resultant, 'opera mini'));
298
                if (isset($aversion[1])) {
299
                    self::$browser->setVersion($aversion[1]);
300
                }
301
            }
302
            self::$browser->setName(Browser::OPERA_MINI);
303
304
            return true;
305 6
        } elseif (stripos(self::$userAgentString, 'OPiOS') !== false) {
306 1
            $aresult = explode('/', stristr(self::$userAgentString, 'OPiOS'));
307 1
            if (isset($aresult[1])) {
308 1
                $aversion = explode(' ', $aresult[1]);
309 1
                self::$browser->setVersion($aversion[0]);
310 1
            }
311 1
            self::$browser->setName(Browser::OPERA_MINI);
312
313 1
            return true;
314 6
        } elseif (stripos(self::$userAgentString, 'opera') !== false) {
315 1
            $resultant = stristr(self::$userAgentString, 'opera');
316 1
            if (preg_match('/Version\/(1[0-2].*)$/', $resultant, $matches)) {
317 1
                if (isset($matches[1])) {
318 1
                    self::$browser->setVersion($matches[1]);
319 1
                }
320 1
            } elseif (preg_match('/\//', $resultant)) {
321
                $aresult = explode('/', str_replace('(', ' ', $resultant));
322
                if (isset($aresult[1])) {
323
                    $aversion = explode(' ', $aresult[1]);
324
                    self::$browser->setVersion($aversion[0]);
325
                }
326
            } else {
327 1
                $aversion = explode(' ', stristr($resultant, 'opera'));
328 1
                self::$browser->setVersion(isset($aversion[1]) ? $aversion[1] : '');
329
            }
330 1
            self::$browser->setName(Browser::OPERA);
331
332 1
            return true;
333 5
        } elseif (stripos(self::$userAgentString, ' OPR/') !== false) {
334 1
            self::$browser->setName(Browser::OPERA);
335 1
            if (preg_match('/OPR\/([\d\.]*)/', self::$userAgentString, $matches)) {
336 1
                if (isset($matches[1])) {
337 1
                    self::$browser->setVersion($matches[1]);
338 1
                }
339 1
            }
340
341 1
            return true;
342
        }
343
344 5
        return false;
345
    }
346
347
    /**
348
     * Determine if the browser is Chrome.
349
     *
350
     * @return bool
351
     */
352 3
    public static function checkBrowserChrome()
353
    {
354 3
        if (stripos(self::$userAgentString, 'Chrome') !== false) {
355 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Chrome'));
356 1
            if (isset($aresult[1])) {
357 1
                $aversion = explode(' ', $aresult[1]);
358 1
                self::$browser->setVersion($aversion[0]);
359 1
            }
360 1
            self::$browser->setName(Browser::CHROME);
361
362 1
            return true;
363 3
        } elseif (stripos(self::$userAgentString, 'CriOS') !== false) {
364 1
            $aresult = explode('/', stristr(self::$userAgentString, 'CriOS'));
365 1
            if (isset($aresult[1])) {
366 1
                $aversion = explode(' ', $aresult[1]);
367 1
                self::$browser->setVersion($aversion[0]);
368 1
            }
369 1
            self::$browser->setName(Browser::CHROME);
370
371 1
            return true;
372
        }
373
374 3
        return false;
375
    }
376
377
    /**
378
     * Determine if the browser is Vivaldi.
379
     *
380
     * @return bool
381
     */
382 5 View Code Duplication
    public static function checkBrowserVivaldi()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
383
    {
384 5
        if (stripos(self::$userAgentString, 'Vivaldi') !== false) {
385 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Vivaldi'));
386 1
            if (isset($aresult[1])) {
387 1
                $aversion = explode(' ', $aresult[1]);
388 1
                self::$browser->setVersion($aversion[0]);
389 1
            }
390 1
            self::$browser->setName(Browser::VIVALDI);
391
392 1
            return true;
393
        }
394
395 5
        return false;
396
    }
397
398
    /**
399
     * Determine if the browser is Microsoft Edge.
400
     *
401
     * @return bool
402
     */
403 6
    public static function checkBrowserEdge()
404
    {
405 6
        if (stripos(self::$userAgentString, 'Edge') !== false) {
406 1
            $version = explode('Edge/', self::$userAgentString);
407 1
            if (isset($version[1])) {
408 1
                self::$browser->setVersion((float)$version[1]);
409 1
            }
410 1
            self::$browser->setName(Browser::EDGE);
411
412 1
            return true;
413
        }
414
415 6
        return false;
416
    }
417
418
    /**
419
     * Determine if the browser is Google Search Appliance.
420
     *
421
     * @return bool
422
     */
423 2 View Code Duplication
    public static function checkBrowserGsa()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
424
    {
425 2
        if (stripos(self::$userAgentString, 'GSA') !== false) {
426
            $aresult = explode('/', stristr(self::$userAgentString, 'GSA'));
427
            if (isset($aresult[1])) {
428
                $aversion = explode(' ', $aresult[1]);
429
                self::$browser->setVersion($aversion[0]);
430
            }
431
            self::$browser->setName(Browser::GSA);
432
433
            return true;
434
        }
435
436 2
        return false;
437
    }
438
439
    /**
440
     * Determine if the browser is WebTv.
441
     *
442
     * @return bool
443
     */
444 7 View Code Duplication
    public static function checkBrowserWebTv()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
445
    {
446 7
        if (stripos(self::$userAgentString, 'webtv') !== false) {
447
            $aresult = explode('/', stristr(self::$userAgentString, 'webtv'));
448
            if (isset($aresult[1])) {
449
                $aversion = explode(' ', $aresult[1]);
450
                self::$browser->setVersion($aversion[0]);
451
            }
452
            self::$browser->setName(Browser::WEBTV);
453
454
            return true;
455
        }
456
457 7
        return false;
458
    }
459
460
    /**
461
     * Determine if the browser is NetPositive.
462
     *
463
     * @return bool
464
     */
465 1
    public static function checkBrowserNetPositive()
466
    {
467 1 View Code Duplication
        if (stripos(self::$userAgentString, 'NetPositive') !== false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
468
            $aresult = explode('/', stristr(self::$userAgentString, 'NetPositive'));
469
            if (isset($aresult[1])) {
470
                $aversion = explode(' ', $aresult[1]);
471
                self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
472
            }
473
            self::$browser->setName(Browser::NETPOSITIVE);
474
475
            return true;
476
        }
477
478 1
        return false;
479
    }
480
481
    /**
482
     * Determine if the browser is Galeon.
483
     *
484
     * @return bool
485
     */
486 5 View Code Duplication
    public static function checkBrowserGaleon()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
487
    {
488 5
        if (stripos(self::$userAgentString, 'galeon') !== false) {
489
            $aresult = explode(' ', stristr(self::$userAgentString, 'galeon'));
490
            $aversion = explode('/', $aresult[0]);
491
            if (isset($aversion[1])) {
492
                self::$browser->setVersion($aversion[1]);
493
            }
494
            self::$browser->setName(Browser::GALEON);
495
496
            return true;
497
        }
498
499 5
        return false;
500
    }
501
502
    /**
503
     * Determine if the browser is Konqueror.
504
     *
505
     * @return bool
506
     */
507 1 View Code Duplication
    public static function checkBrowserKonqueror()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
508
    {
509 1
        if (stripos(self::$userAgentString, 'Konqueror') !== false) {
510
            $aresult = explode(' ', stristr(self::$userAgentString, 'Konqueror'));
511
            $aversion = explode('/', $aresult[0]);
512
            if (isset($aversion[1])) {
513
                self::$browser->setVersion($aversion[1]);
514
            }
515
            self::$browser->setName(Browser::KONQUEROR);
516
517
            return true;
518
        }
519
520 1
        return false;
521
    }
522
523
    /**
524
     * Determine if the browser is iCab.
525
     *
526
     * @return bool
527
     */
528 1 View Code Duplication
    public static function checkBrowserIcab()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
529
    {
530 1
        if (stripos(self::$userAgentString, 'icab') !== false) {
531
            $aversion = explode(' ', stristr(str_replace('/', ' ', self::$userAgentString), 'icab'));
532
            if (isset($aversion[1])) {
533
                self::$browser->setVersion($aversion[1]);
534
            }
535
            self::$browser->setName(Browser::ICAB);
536
537
            return true;
538
        }
539
540 1
        return false;
541
    }
542
543
    /**
544
     * Determine if the browser is OmniWeb.
545
     *
546
     * @return bool
547
     */
548 3 View Code Duplication
    public static function checkBrowserOmniWeb()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
549
    {
550 3
        if (stripos(self::$userAgentString, 'omniweb') !== false) {
551
            $aresult = explode('/', stristr(self::$userAgentString, 'omniweb'));
552
            $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : '');
553
            self::$browser->setVersion($aversion[0]);
554
            self::$browser->setName(Browser::OMNIWEB);
555
556
            return true;
557
        }
558
559 3
        return false;
560
    }
561
562
    /**
563
     * Determine if the browser is Phoenix.
564
     *
565
     * @return bool
566
     */
567 1
    public static function checkBrowserPhoenix()
568
    {
569 1
        if (stripos(self::$userAgentString, 'Phoenix') !== false) {
570
            $aversion = explode('/', stristr(self::$userAgentString, 'Phoenix'));
571
            if (isset($aversion[1])) {
572
                self::$browser->setVersion($aversion[1]);
573
            }
574
            self::$browser->setName(Browser::PHOENIX);
575
576
            return true;
577
        }
578
579 1
        return false;
580
    }
581
582
    /**
583
     * Determine if the browser is Firebird.
584
     *
585
     * @return bool
586
     */
587 1
    public static function checkBrowserFirebird()
588
    {
589 1
        if (stripos(self::$userAgentString, 'Firebird') !== false) {
590
            $aversion = explode('/', stristr(self::$userAgentString, 'Firebird'));
591
            if (isset($aversion[1])) {
592
                self::$browser->setVersion($aversion[1]);
593
            }
594
            self::$browser->setName(Browser::FIREBIRD);
595
596
            return true;
597
        }
598
599 1
        return false;
600
    }
601
602
    /**
603
     * Determine if the browser is Netscape Navigator 9+.
604
     *
605
     * @return bool
606
     */
607 5
    public static function checkBrowserNetscapeNavigator9Plus()
608
    {
609 5
        if (stripos(self::$userAgentString, 'Firefox') !== false &&
610 2
            preg_match('/Navigator\/([^ ]*)/i', self::$userAgentString, $matches)
611 5
        ) {
612
            if (isset($matches[1])) {
613
                self::$browser->setVersion($matches[1]);
614
            }
615
            self::$browser->setName(Browser::NETSCAPE_NAVIGATOR);
616
617
            return true;
618 5
        } elseif (stripos(self::$userAgentString, 'Firefox') === false &&
619 4
            preg_match('/Netscape6?\/([^ ]*)/i', self::$userAgentString, $matches)
620 5
        ) {
621
            if (isset($matches[1])) {
622
                self::$browser->setVersion($matches[1]);
623
            }
624
            self::$browser->setName(Browser::NETSCAPE_NAVIGATOR);
625
626
            return true;
627
        }
628
629 5
        return false;
630
    }
631
632
    /**
633
     * Determine if the browser is Shiretoko.
634
     *
635
     * @return bool
636
     */
637 1
    public static function checkBrowserShiretoko()
638
    {
639 1
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
640
            preg_match('/Shiretoko\/([^ ]*)/i', self::$userAgentString, $matches)
641 1
        ) {
642
            if (isset($matches[1])) {
643
                self::$browser->setVersion($matches[1]);
644
            }
645
            self::$browser->setName(Browser::SHIRETOKO);
646
647
            return true;
648
        }
649
650 1
        return false;
651
    }
652
653
    /**
654
     * Determine if the browser is Ice Cat.
655
     *
656
     * @return bool
657
     */
658 1
    public static function checkBrowserIceCat()
659
    {
660 1
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
661
            preg_match('/IceCat\/([^ ]*)/i', self::$userAgentString, $matches)
662 1
        ) {
663
            if (isset($matches[1])) {
664
                self::$browser->setVersion($matches[1]);
665
            }
666
            self::$browser->setName(Browser::ICECAT);
667
668
            return true;
669
        }
670
671 1
        return false;
672
    }
673
674
    /**
675
     * Determine if the browser is Nokia.
676
     *
677
     * @return bool
678
     */
679 2
    public static function checkBrowserNokia()
680
    {
681 2
        if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", self::$userAgentString, $matches)) {
682
            self::$browser->setVersion($matches[2]);
683
            if (stripos(self::$userAgentString, 'Series60') !== false ||
684
                strpos(self::$userAgentString, 'S60') !== false
685
            ) {
686
                self::$browser->setName(Browser::NOKIA_S60);
687
            } else {
688
                self::$browser->setName(Browser::NOKIA);
689
            }
690
691
            return true;
692
        }
693
694 2
        return false;
695
    }
696
697
    /**
698
     * Determine if the browser is Firefox.
699
     *
700
     * @return bool
701
     */
702 4 View Code Duplication
    public static function checkBrowserFirefox()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
703
    {
704 4
        if (stripos(self::$userAgentString, 'safari') === false) {
705 4
            if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) {
706 2
                if (isset($matches[1])) {
707 2
                    self::$browser->setVersion($matches[1]);
708 2
                }
709 2
                self::$browser->setName(Browser::FIREFOX);
710
711 2
                return true;
712 2
            } elseif (preg_match('/Firefox$/i', self::$userAgentString, $matches)) {
713
                self::$browser->setVersion('');
714
                self::$browser->setName(Browser::FIREFOX);
715
716
                return true;
717
            }
718 2
        }
719
720 3
        return false;
721
    }
722
723
    /**
724
     * Determine if the browser is SeaMonkey.
725
     *
726
     * @return bool
727
     */
728 5 View Code Duplication
    public static function checkBrowserSeaMonkey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
729
    {
730 5
        if (stripos(self::$userAgentString, 'safari') === false) {
731 5
            if (preg_match("/SeaMonkey[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) {
732 1
                if (isset($matches[1])) {
733 1
                    self::$browser->setVersion($matches[1]);
734 1
                }
735 1
                self::$browser->setName(Browser::SEAMONKEY);
736
737 1
                return true;
738 4
            } elseif (preg_match('/SeaMonkey$/i', self::$userAgentString, $matches)) {
739
                self::$browser->setVersion('');
740
                self::$browser->setName(Browser::SEAMONKEY);
741
742
                return true;
743
            }
744 4
        }
745
746 4
        return false;
747
    }
748
749
    /**
750
     * Determine if the browser is Iceweasel.
751
     *
752
     * @return bool
753
     */
754 1 View Code Duplication
    public static function checkBrowserIceweasel()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
755
    {
756 1
        if (stripos(self::$userAgentString, 'Iceweasel') !== false) {
757
            $aresult = explode('/', stristr(self::$userAgentString, 'Iceweasel'));
758
            if (isset($aresult[1])) {
759
                $aversion = explode(' ', $aresult[1]);
760
                self::$browser->setVersion($aversion[0]);
761
            }
762
            self::$browser->setName(Browser::ICEWEASEL);
763
764
            return true;
765
        }
766
767 1
        return false;
768
    }
769
770
    /**
771
     * Determine if the browser is Mozilla.
772
     *
773
     * @return bool
774
     */
775 1
    public static function checkBrowserMozilla()
776
    {
777 1
        if (stripos(self::$userAgentString, 'mozilla') !== false &&
778 1
            preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString) &&
779
            stripos(self::$userAgentString, 'netscape') === false
780 1
        ) {
781
            $aversion = explode(' ', stristr(self::$userAgentString, 'rv:'));
782
            preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString, $aversion);
783
            self::$browser->setVersion(str_replace('rv:', '', $aversion[0]));
784
            self::$browser->setName(Browser::MOZILLA);
785
786
            return true;
787 1
        } elseif (stripos(self::$userAgentString, 'mozilla') !== false &&
788 1
            preg_match('/rv:[0-9]\.[0-9]/i', self::$userAgentString) &&
789
            stripos(self::$userAgentString, 'netscape') === false
790 1
        ) {
791
            $aversion = explode('', stristr(self::$userAgentString, 'rv:'));
792
            self::$browser->setVersion(str_replace('rv:', '', $aversion[0]));
793
            self::$browser->setName(Browser::MOZILLA);
794
795
            return true;
796 1
        } elseif (stripos(self::$userAgentString, 'mozilla') !== false &&
797 1
            preg_match('/mozilla\/([^ ]*)/i', self::$userAgentString, $matches) &&
798
            stripos(self::$userAgentString, 'netscape') === false
799 1
        ) {
800
            if (isset($matches[1])) {
801
                self::$browser->setVersion($matches[1]);
802
            }
803
            self::$browser->setName(Browser::MOZILLA);
804
805
            return true;
806
        }
807
808 1
        return false;
809
    }
810
811
    /**
812
     * Determine if the browser is Lynx.
813
     *
814
     * @return bool
815
     */
816 1 View Code Duplication
    public static function checkBrowserLynx()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
817
    {
818 1
        if (stripos(self::$userAgentString, 'lynx') !== false) {
819
            $aresult = explode('/', stristr(self::$userAgentString, 'Lynx'));
820
            $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ''));
821
            self::$browser->setVersion($aversion[0]);
822
            self::$browser->setName(Browser::LYNX);
823
824
            return true;
825
        }
826
827 1
        return false;
828
    }
829
830
    /**
831
     * Determine if the browser is Amaya.
832
     *
833
     * @return bool
834
     */
835 1 View Code Duplication
    public static function checkBrowserAmaya()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
836
    {
837 1
        if (stripos(self::$userAgentString, 'amaya') !== false) {
838
            $aresult = explode('/', stristr(self::$userAgentString, 'Amaya'));
839
            if (isset($aresult[1])) {
840
                $aversion = explode(' ', $aresult[1]);
841
                self::$browser->setVersion($aversion[0]);
842
            }
843
            self::$browser->setName(Browser::AMAYA);
844
845
            return true;
846
        }
847
848 1
        return false;
849
    }
850
851
    /**
852
     * Determine if the browser is Safari.
853
     *
854
     * @return bool
855
     */
856 2
    public static function checkBrowserSafari()
857
    {
858 2
        if (stripos(self::$userAgentString, 'Safari') !== false) {
859 1
            $aresult = explode('/', stristr(self::$userAgentString, 'Version'));
860 1
            if (isset($aresult[1])) {
861 1
                $aversion = explode(' ', $aresult[1]);
862 1
                self::$browser->setVersion($aversion[0]);
863 1
            } else {
864
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
865
            }
866 1
            self::$browser->setName(Browser::SAFARI);
867
868 1
            return true;
869
        }
870
871 1
        return false;
872
    }
873
874
    /**
875
     * Determine if the browser is Yandex.
876
     *
877
     * @return bool
878
     */
879 3 View Code Duplication
    public static function checkBrowserYandex()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
880
    {
881 3
        if (stripos(self::$userAgentString, 'YaBrowser') !== false) {
882 1
            $aresult = explode('/', stristr(self::$userAgentString, 'YaBrowser'));
883 1
            if (isset($aresult[1])) {
884 1
                $aversion = explode(' ', $aresult[1]);
885 1
                self::$browser->setVersion($aversion[0]);
886 1
            }
887 1
            self::$browser->setName(Browser::YANDEX);
888
889 1
            return true;
890
        }
891
892 3
        return false;
893
    }
894
895
    /**
896
     * Determine if the browser is Android.
897
     *
898
     * @return bool
899
     */
900 3
    public static function checkBrowserAndroid()
901
    {
902
        // Navigator
903 3
        if (stripos(self::$userAgentString, 'Android') !== false) {
904
            if (preg_match('/Version\/([\d\.]*)/i', self::$userAgentString, $matches)) {
905
                if (isset($matches[1])) {
906
                    self::$browser->setVersion($matches[1]);
907
                }
908
            } else {
909
                self::$browser->setVersion(Browser::VERSION_UNKNOWN);
910
            }
911
            self::$browser->setName(Browser::NAVIGATOR);
912
913
            return true;
914
        }
915
916 3
        return false;
917
    }
918
}
919