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

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.0741

Importance

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