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   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 95.83%

Importance

Changes 13
Bugs 0 Features 1
Metric Value
wmc 9
c 13
b 0
f 1
lcom 1
cbo 6
dl 0
loc 122
ccs 23
cts 24
cp 0.9583
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A hasResult() 0 8 2
B parse() 0 28 2
A hydrateBrowser() 0 10 3
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