GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e50d76...32d930 )
by Martin
06:12
created

DonatjUAParser::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4286
cc 2
eloc 3
nc 2
nop 0
crap 2.0625
1
<?php
2
namespace UserAgentParser\Provider;
3
4
use UserAgentParser\Exception;
5
use UserAgentParser\Model;
6
7
class DonatjUAParser extends AbstractProvider
8
{
9
    /**
10
     * Name of the provider
11
     *
12
     * @var string
13
     */
14
    protected $name = 'DonatjUAParser';
15
16
    /**
17
     * Homepage of the provider
18
     *
19
     * @var string
20
     */
21
    protected $homepage = 'https://github.com/donatj/PhpUserAgent';
22
23
    /**
24
     * Composer package name
25
     *
26
     * @var string
27
     */
28
    protected $packageName = 'donatj/phpuseragentparser';
29
30
    protected $detectionCapabilities = [
31
32
        'browser' => [
33
            'name'    => true,
34
            'version' => true,
35
        ],
36
37
        'renderingEngine' => [
38
            'name'    => false,
39
            'version' => false,
40
        ],
41
42
        'operatingSystem' => [
43
            'name'    => false,
44
            'version' => false,
45
        ],
46
47
        'device' => [
48
            'model'    => false,
49
            'brand'    => false,
50
            'type'     => false,
51
            'isMobile' => false,
52
            'isTouch'  => false,
53
        ],
54
55
        'bot' => [
56
            'isBot' => false,
57
            'name'  => false,
58
            'type'  => false,
59
        ],
60
    ];
61
62 8
    public function __construct()
63
    {
64 8
        if (! function_exists('parse_user_agent')) {
65
            throw new Exception\PackageNotLoadedException('You need to install ' . $this->getHomepage() . ' to use this provider');
66
        }
67 8
    }
68
69
    /**
70
     *
71
     * @param array $resultRaw
72
     *
73
     * @return bool
74
     */
75 2
    private function hasResult(array $resultRaw)
76
    {
77 2
        if ($this->isRealResult($resultRaw['browser'])) {
78 1
            return true;
79
        }
80
81 1
        return false;
82
    }
83
84
    /**
85
     *
86
     * @param Model\Browser $browser
87
     * @param array         $resultRaw
88
     */
89 1
    private function hydrateBrowser(Model\Browser $browser, array $resultRaw)
90
    {
91 1
        if ($this->isRealResult($resultRaw['browser']) === true) {
92 1
            $browser->setName($resultRaw['browser']);
93 1
        }
94
95 1
        if ($this->isRealResult($resultRaw['version']) === true) {
96 1
            $browser->getVersion()->setComplete($resultRaw['version']);
97 1
        }
98 1
    }
99
100 2
    public function parse($userAgent, array $headers = [])
101
    {
102 2
        $resultRaw = parse_user_agent($userAgent);
103
104 2
        if ($this->hasResult($resultRaw) !== true) {
105 1
            throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
106
        }
107
108
        /*
109
         * Hydrate the model
110
         */
111 1
        $result = new Model\UserAgent();
112 1
        $result->setProviderResultRaw($resultRaw);
113
114
        /*
115
         * Bot detection - is currently not possible!
116
         */
117
118
        /*
119
         * hydrate the result
120
         */
121 1
        $this->hydrateBrowser($result->getBrowser(), $resultRaw);
122
        // renderingEngine not available
123
        // os is mixed with device informations
124
        // device is mixed with os
125
126 1
        return $result;
127
    }
128
}
129