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::hydrateBrowser()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4286
cc 3
eloc 5
nc 4
nop 2
crap 3
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