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.

DonatjUAParser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 123
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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