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
Pull Request — master (#42)
by Martin
04:00
created

DonatjUAParser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 96.15%

Importance

Changes 12
Bugs 0 Features 1
Metric Value
wmc 11
c 12
b 0
f 1
lcom 1
cbo 6
dl 0
loc 111
ccs 25
cts 26
cp 0.9615
rs 10

6 Methods

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