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 ( 2ecc0e...ca3a96 )
by Martin
08:39
created

WhichBrowser::hydrateOperatingSystem()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
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
use WhichBrowser\Parser as WhichBrowserParser;
7
8
class WhichBrowser extends AbstractProvider
9
{
10
    /**
11
     * Used for unitTests mocking
12
     *
13
     * @var WhichBrowserParser
14
     */
15
    private $parser;
16
17 2
    public function getName()
18
    {
19 2
        return 'WhichBrowser';
20
    }
21
22 2
    public function getComposerPackageName()
23
    {
24 2
        return 'whichbrowser/parser';
25
    }
26
27
    /**
28
     *
29
     * @param  array              $headers
30
     * @return WhichBrowserParser
31
     */
32 8
    public function getParser(array $headers)
33
    {
34 8
        if ($this->parser !== null) {
35 7
            return $this->parser;
36
        }
37
38 1
        return new WhichBrowserParser($headers);
39
    }
40
41
    /**
42
     *
43
     * @param Model\Bot                   $bot
44
     * @param \WhichBrowser\Model\Browser $browserRaw
45
     */
46 1
    private function hydrateBot(Model\Bot $bot, \WhichBrowser\Model\Browser $browserRaw)
47
    {
48 1
        $bot->setIsBot(true);
49
50 1
        if ($this->isRealResult($browserRaw->getName()) === true) {
51 1
            $bot->setName($browserRaw->getName());
52
        }
53 1
    }
54
55
    /**
56
     *
57
     * @param Model\Browser               $browser
58
     * @param \WhichBrowser\Model\Browser $browserRaw
59
     */
60 5
    private function hydrateBrowser(Model\Browser $browser, \WhichBrowser\Model\Browser $browserRaw)
61
    {
62 5 View Code Duplication
        if ($this->isRealResult($browserRaw->getName()) === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63 1
            $browser->setName($browserRaw->getName());
64
65 1
            if ($this->isRealResult($browserRaw->getVersion()) === true) {
66 1
                $browser->getVersion()->setComplete($browserRaw->getVersion());
67
            }
68
69 1
            return;
70
        }
71
72 4
        if (isset($browserRaw->using) && $browserRaw->using instanceof \WhichBrowser\Model\Using) {
73
            /* @var $usingRaw \WhichBrowser\Model\Using */
74 1
            $usingRaw = $browserRaw->using;
75
76 1 View Code Duplication
            if ($this->isRealResult($usingRaw->getName()) === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77 1
                $browser->setName($usingRaw->getName());
78
79 1
                if ($this->isRealResult($usingRaw->getVersion()) === true) {
80 1
                    $browser->getVersion()->setComplete($usingRaw->getVersion());
81
                }
82
            }
83
        }
84 4
    }
85
86
    /**
87
     *
88
     * @param Model\RenderingEngine      $engine
89
     * @param \WhichBrowser\Model\Engine $engineRaw
90
     */
91 5 View Code Duplication
    private function hydrateRenderingEngine(Model\RenderingEngine $engine, \WhichBrowser\Model\Engine $engineRaw)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93 5
        if ($this->isRealResult($engineRaw->getName()) === true) {
94 1
            $engine->setName($engineRaw->getName());
95
        }
96
97 5
        if ($this->isRealResult($engineRaw->getVersion()) === true) {
98 1
            $engine->getVersion()->setComplete($engineRaw->getVersion());
99
        }
100 5
    }
101
102
    /**
103
     *
104
     * @param Model\OperatingSystem  $os
105
     * @param \WhichBrowser\Model\Os $osRaw
106
     */
107 5 View Code Duplication
    private function hydrateOperatingSystem(Model\OperatingSystem $os, \WhichBrowser\Model\Os $osRaw)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
    {
109 5
        if ($this->isRealResult($osRaw->getName()) === true) {
110 1
            $os->setName($osRaw->getName());
111
        }
112
113 5
        if ($this->isRealResult($osRaw->getVersion()) === true) {
114 1
            $os->getVersion()->setComplete($osRaw->getVersion());
115
        }
116 5
    }
117
118
    /**
119
     *
120
     * @param Model\Device               $device
121
     * @param \WhichBrowser\Model\Device $deviceRaw
122
     * @param WhichBrowserParser         $parser
123
     */
124 5
    private function hydrateDevice(Model\Device $device, \WhichBrowser\Model\Device $deviceRaw, WhichBrowserParser $parser)
125
    {
126 5
        if ($this->isRealResult($deviceRaw->getModel()) === true) {
127 1
            $device->setModel($deviceRaw->getModel());
128
        }
129
130 5
        if ($this->isRealResult($deviceRaw->getManufacturer()) === true) {
131 1
            $device->setBrand($deviceRaw->getManufacturer());
132
        }
133
134 5
        if ($this->isRealResult($parser->getType()) === true) {
135 1
            $device->setType($parser->getType());
136
        }
137
138 5
        if ($parser->isType('mobile', 'tablet', 'ereader', 'media', 'watch', 'camera', 'gaming:portable') === true) {
139 1
            $device->setIsMobile(true);
140
        }
141 5
    }
142
143 7
    public function parse($userAgent, array $headers = [])
144
    {
145 7
        $headers['User-Agent'] = $userAgent;
146
147 7
        $parser = $this->getParser($headers);
148
149
        /*
150
         * No result found?
151
         */
152 7
        if ($parser->isDetected() !== true) {
153 1
            throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
154
        }
155
156
        /*
157
         * Hydrate the model
158
         */
159 6
        $result = new Model\UserAgent();
160 6
        $result->setProviderResultRaw($parser->toArray());
161
162
        /*
163
         * Bot detection
164
         */
165 6
        if ($parser->getType() === 'bot') {
166 1
            $this->hydrateBot($result->getBot(), $parser->browser);
167
168 1
            return $result;
169
        }
170
171
        /*
172
         * hydrate the result
173
         */
174 5
        $this->hydrateBrowser($result->getBrowser(), $parser->browser);
175 5
        $this->hydrateRenderingEngine($result->getRenderingEngine(), $parser->engine);
176 5
        $this->hydrateOperatingSystem($result->getOperatingSystem(), $parser->os);
177 5
        $this->hydrateDevice($result->getDevice(), $parser->device, $parser);
178
179 5
        return $result;
180
    }
181
}
182