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 (#59)
by Martin
02:47
created

Wurfl   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 237
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 13
Bugs 0 Features 2
Metric Value
wmc 21
c 13
b 0
f 2
lcom 1
cbo 11
dl 0
loc 237
ccs 78
cts 78
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getVersion() 0 15 2
A getUpdateDate() 0 14 2
A getParser() 0 4 1
A hasResult() 0 8 4
A hydrateBrowser() 0 5 1
A hydrateOperatingSystem() 0 5 1
B hydrateDevice() 0 23 6
B parse() 0 44 3
1
<?php
2
namespace UserAgentParser\Provider;
3
4
use UserAgentParser\Exception\NoResultFoundException;
5
use UserAgentParser\Model;
6
use Wurfl\CustomDevice;
7
use Wurfl\Manager as WurflManager;
8
9
class Wurfl extends AbstractProvider
10
{
11
    /**
12
     * Name of the provider
13
     *
14
     * @var string
15
     */
16
    protected $name = 'Wurfl';
17
18
    /**
19
     * Homepage of the provider
20
     *
21
     * @var string
22
     */
23
    protected $homepage = 'https://github.com/mimmi20/Wurfl';
24
25
    /**
26
     * Composer package name
27
     *
28
     * @var string
29
     */
30
    protected $packageName = 'mimmi20/wurfl';
31
32
    protected $detectionCapabilities = [
33
34
        'browser' => [
35
            'name'    => true,
36
            'version' => true,
37
        ],
38
39
        'renderingEngine' => [
40
            'name'    => false,
41
            'version' => false,
42
        ],
43
44
        'operatingSystem' => [
45
            'name'    => true,
46
            'version' => true,
47
        ],
48
49
        'device' => [
50
            'model'    => true,
51
            'brand'    => true,
52
            'type'     => true,
53
            'isMobile' => true,
54
            'isTouch'  => true,
55
        ],
56
57
        'bot' => [
58
            'isBot' => true,
59
            'name'  => false,
60
            'type'  => false,
61
        ],
62
    ];
63
64
    protected $defaultValues = [
65
66
        'general' => [
67
            '/^Generic$/i',
68
        ],
69
70
        'device' => [
71
72
            'model' => [
73
                '/^Android/i',
74
                '/^Firefox/i',
75
                '/^unrecognized/i',
76
                '/^Windows/i',
77
            ],
78 15
        ],
79
    ];
80 15
81 15
    /**
82
     *
83 2
     * @var WurflManager
84
     */
85 2
    private $parser;
86 2
87
    /**
88 2
     *
89 1
     * @param WurflManager $parser
90 1
     */
91 1
    public function __construct(WurflManager $parser)
92
    {
93 1
        $this->parser = $parser;
94
    }
95
96 1
    public function getVersion()
97
    {
98
        $version      = $this->getParser()->getWurflInfo()->version;
99 2
        $versionParts = explode(' - ', $version);
100
101
        if (count($versionParts) === 2) {
102 2
            $versionPart = $versionParts[0];
103
            $versionPart = str_replace('for API', '', $versionPart);
104 2
            $versionPart = str_replace(', db.scientiamobile.com', '', $versionPart);
105 1
106
            return trim($versionPart);
107
        }
108 1
109 1
        return;
110
    }
111 1
112
    public function getUpdateDate()
113
    {
114
        // 2015-10-16 11:09:44 -0400
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
115
        $lastUpdated = $this->getParser()->getWurflInfo()->lastUpdated;
116
117
        if ($lastUpdated == '') {
118 11
            return;
119
        }
120 11
121
        $date = \DateTime::createFromFormat('Y-m-d H:i:s O', $lastUpdated);
122
        $date->setTimezone(new \DateTimeZone('UTC'));
123
124
        return $date;
125
    }
126
127
    /**
128 6
     *
129
     * @return WurflManager
130 6
     */
131 5
    public function getParser()
132
    {
133
        return $this->parser;
134 1
    }
135
136
    /**
137
     *
138
     * @param  CustomDevice $device
139
     * @return boolean
140
     */
141
    private function hasResult(CustomDevice $device)
142 4
    {
143
        if ($device->id !== null && $device->id != '' && $device->id !== 'generic') {
144 4
            return true;
145 2
        }
146
147
        return false;
148 2
    }
149
150
    /**
151 2
     *
152 2
     * @param Model\Browser $browser
153 2
     * @param CustomDevice  $deviceRaw
154 2
     */
155 2
    private function hydrateBrowser(Model\Browser $browser, CustomDevice $deviceRaw)
156 2
    {
157 2
        $browser->setName($deviceRaw->getVirtualCapability('advertised_browser'));
158
        $browser->getVersion()->setComplete($deviceRaw->getVirtualCapability('advertised_browser_version'));
159 2
    }
160 2
161 1
    /**
162
     *
163 1
     * @param Model\OperatingSystem $os
164
     * @param CustomDevice          $deviceRaw
165 1
     */
166
    private function hydrateOperatingSystem(Model\OperatingSystem $os, CustomDevice $deviceRaw)
167
    {
168
        $os->setName($deviceRaw->getVirtualCapability('advertised_device_os'));
169
        $os->getVersion()->setComplete($deviceRaw->getVirtualCapability('advertised_device_os_version'));
170
    }
171
172
    /**
173 4
     *
174
     * @param Model\UserAgent $device
175 4
     * @param CustomDevice    $deviceRaw
176 4
     */
177 4
    private function hydrateDevice(Model\Device $device, CustomDevice $deviceRaw)
178
    {
179
        if ($deviceRaw->getVirtualCapability('is_full_desktop') !== 'true') {
180
            if ($this->isRealResult($deviceRaw->getCapability('model_name'), 'device', 'model') === true) {
181
                $device->setModel($deviceRaw->getCapability('model_name'));
182
            }
183
184 4
            if ($this->isRealResult($deviceRaw->getCapability('brand_name')) === true) {
185
                $device->setBrand($deviceRaw->getCapability('brand_name'));
186 4
            }
187 4
188 4
            if ($deviceRaw->getVirtualCapability('is_mobile') === 'true') {
189
                $device->setIsMobile(true);
190
            }
191
192
            if ($deviceRaw->getVirtualCapability('is_touchscreen') === 'true') {
193
                $device->setIsTouch(true);
194
            }
195 4
        }
196
197 4
        // @see the list of all types http://web.wurfl.io/
198 4
        $device->setType($deviceRaw->getVirtualCapability('form_factor'));
199 1
    }
200 1
201
    public function parse($userAgent, array $headers = [])
202 4
    {
203 2
        $parser = $this->getParser();
204 2
205
        $deviceRaw = $parser->getDeviceForUserAgent($userAgent);
206 4
207 2
        /*
208 2
         * No result found?
209
         */
210 4
        if ($this->hasResult($deviceRaw) !== true) {
211 2
            throw new NoResultFoundException('No result found for user agent: ' . $userAgent);
212 2
        }
213 4
214
        /*
215
         * Hydrate the model
216 4
         */
217 4
        $result = new Model\UserAgent();
218
        $result->setProviderResultRaw([
219 6
            'virtual' => $deviceRaw->getAllVirtualCapabilities(),
220
            'all'     => $deviceRaw->getAllCapabilities(),
221 6
        ]);
222
223 6
        /*
224
         * Bot detection
225
         */
226
        if ($deviceRaw->getVirtualCapability('is_robot') === 'true') {
227
            $bot = $result->getBot();
228 6
            $bot->setIsBot(true);
229 1
230
            // brand_name seems to be always google, so dont use it
231
232
            return $result;
233
        }
234
235 5
        /*
236 5
         * hydrate the result
237 5
         */
238 5
        $this->hydrateBrowser($result->getBrowser(), $deviceRaw);
239 5
        // renderingEngine not available
240
        $this->hydrateOperatingSystem($result->getOperatingSystem(), $deviceRaw);
241
        $this->hydrateDevice($result->getDevice(), $deviceRaw);
242
243
        return $result;
244 5
    }
245
}
246