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 ( 0994ac...8bf298 )
by Martin
04:01
created

Wurfl::isRealModel()   D

Complexity

Conditions 10
Paths 9

Size

Total Lines 36
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 15.8818

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 36
ccs 11
cts 18
cp 0.6111
rs 4.8197
cc 10
eloc 18
nc 9
nop 1
crap 15.8818

1 Method

Rating   Name   Duplication   Size   Complexity  
A Wurfl::hasResult() 0 8 4

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace UserAgentParser\Provider;
3
4
use UserAgentParser\Exception;
5
use UserAgentParser\Model;
6
use Wurfl\CustomDevice;
7
use Wurfl\Manager as WurflManager;
8
9
class Wurfl extends AbstractProvider
10
{
11
    protected $defaultValues = [
12
        'Generic',
13
    ];
14
15
    /**
16
     *
17
     * @var WurflManager
18
     */
19
    private $parser;
20
21
    /**
22
     *
23
     * @param WurflManager $parser
24
     */
25 10
    public function __construct(WurflManager $parser)
26
    {
27 10
        $this->setParser($parser);
28 10
    }
29
30 1
    public function getName()
31
    {
32 1
        return 'Wurfl';
33
    }
34
35 1
    public function getComposerPackageName()
36
    {
37 1
        return 'mimmi20/wurfl';
38
    }
39
40 1
    public function getVersion()
41
    {
42 1
        return $this->getParser()->getWurflInfo()->version;
43
    }
44
45
    /**
46
     *
47
     * @param WurflManager $parser
48
     */
49 10
    public function setParser(WurflManager $parser)
50
    {
51 10
        $this->parser = $parser;
52 10
    }
53
54
    /**
55
     *
56
     * @return WurflManager
57
     */
58 8
    public function getParser()
59
    {
60 8
        return $this->parser;
61
    }
62
63
    /**
64
     * @param mixed $value
65
     *
66
     * @return bool
67
     */
68 4
    private function isRealDeviceModel($value)
69
    {
70 4
        if ($this->isRealResult($value) !== true) {
71 2
            return false;
72
        }
73
74 2
        $value = (string) $value;
75
76
        $defaultValues = [
77 2
            'Android',
78 2
            'Firefox',
79 2
            'unrecognized',
80 2
            'Windows Mobile',
81 2
            'Windows Phone',
82 2
            'Windows RT',
83 2
        ];
84
85 2
        foreach ($defaultValues as $defaultValue) {
86 2
            if (substr($value, 0, strlen($defaultValue)) == $defaultValue) {
87 1
                return false;
88
            }
89 1
        }
90
91 1
        return true;
92
    }
93
94
    /**
95
     *
96
     * @param  CustomDevice $device
97
     * @return boolean
98
     */
99 6
    private function hasResult(CustomDevice $device)
100
    {
101 6
        if ($device->id !== null && $device->id != '' && $device->id !== 'generic') {
102 5
            return true;
103
        }
104
105 1
        return false;
106
    }
107
108 6
    public function parse($userAgent, array $headers = [])
109
    {
110 6
        $parser = $this->getParser();
111
112 6
        $deviceRaw = $parser->getDeviceForUserAgent($userAgent);
113
114
        /*
115
         * No result found?
116
         */
117 6
        if ($this->hasResult($deviceRaw) !== true) {
118 1
            throw new Exception\NoResultFoundException('No result found for user agent: ' . $userAgent);
119
        }
120
121
        /*
122
         * Hydrate the model
123
         */
124 5
        $result = new Model\UserAgent();
125 5
        $result->setProviderResultRaw([
126 5
            'virtual' => $deviceRaw->getAllVirtualCapabilities(),
127 5
            'all'     => $deviceRaw->getAllCapabilities(),
128 5
        ]);
129
130
        /*
131
         * Bot detection
132
         */
133 5
        if ($deviceRaw->getVirtualCapability('is_robot') === 'true') {
134 1
            $bot = $result->getBot();
135 1
            $bot->setIsBot(true);
136
137
            // brand_name seems to be always google, so dont use it
138
139 1
            return $result;
140
        }
141
142
        /*
143
         * browser
144
         */
145 4
        $browser = $result->getBrowser();
146
147 4
        $browser->setName($deviceRaw->getVirtualCapability('advertised_browser'));
148 4
        $browser->getVersion()->setComplete($deviceRaw->getVirtualCapability('advertised_browser_version'));
149
150
        /*
151
         * operatingSystem
152
         */
153 4
        $operatingSystem = $result->getOperatingSystem();
154
155 4
        $operatingSystem->setName($deviceRaw->getVirtualCapability('advertised_device_os'));
156 4
        $operatingSystem->getVersion()->setComplete($deviceRaw->getVirtualCapability('advertised_device_os_version'));
157
158
        /*
159
         * device
160
         */
161 4
        $device = $result->getDevice();
162
163 4
        if ($deviceRaw->getVirtualCapability('is_full_desktop') !== 'true') {
164 4
            if ($this->isRealDeviceModel($deviceRaw->getCapability('model_name')) === true) {
165 1
                $device->setModel($deviceRaw->getCapability('model_name'));
166
            }
167
168 4
            if ($this->isRealResult($deviceRaw->getCapability('brand_name')) === true) {
169 2
                $device->setBrand($deviceRaw->getCapability('brand_name'));
170
            }
171
172 4
            if ($deviceRaw->getVirtualCapability('is_mobile') === 'true') {
173 2
                $device->setIsMobile(true);
174
            }
175
176 4
            if ($deviceRaw->getVirtualCapability('is_touchscreen') === 'true') {
177 2
                $device->setIsTouch(true);
178
            }
179
        }
180
181
        // @see the list of all types http://web.wurfl.io/
182 4
        $device->setType($deviceRaw->getVirtualCapability('form_factor'));
183
184 4
        return $result;
185
    }
186
}
187