Woothee::getVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * CSP
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2014 Kenji Suzuki
8
 * @link       https://github.com/kenjis/php-csp-nonce-source
9
 */
10
11
namespace Kenjis\Csp\Browser;
12
13
use Woothee\Classifier;
14
15
/**
16
 * Browser Detector using woothee-php
17
 */
18
class Woothee implements AdapterInterface
19
{
20
    private $browser = [];
21
22
    /**
23
     * @param string $userAgent user agent string
24
     */
25
    public function __construct($userAgent)
26
    {
27
        $classifier = new Classifier;
28
        $this->browser = $classifier->parse($userAgent);;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getName()
35
    {
36
        return $this->browser['name'];
37
    }
38
39
    /**
40
     * @return int
41
     */
42
    public function getVersion()
43
    {
44
        $tmp = explode('.', $this->browser['version']);
45
        return (int) $tmp[0];
46
    }
47
}
48