This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace UserAgentParser\Provider; |
||
3 | |||
4 | use EndorphinStudio\Detector as EndorphinDetector; |
||
5 | use UserAgentParser\Exception\NoResultFoundException; |
||
6 | use UserAgentParser\Exception\PackageNotLoadedException; |
||
7 | use UserAgentParser\Model; |
||
8 | |||
9 | /** |
||
10 | * Abstraction for piwik/device-detector |
||
11 | * |
||
12 | * @author Martin Keckeis <[email protected]> |
||
13 | * @license MIT |
||
14 | * @see https://github.com/EndorphinDetector-studio/browser-detector |
||
15 | */ |
||
16 | class Endorphin extends AbstractProvider |
||
17 | { |
||
18 | /** |
||
19 | * Name of the provider |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $name = 'Endorphin'; |
||
24 | |||
25 | /** |
||
26 | * Homepage of the provider |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $homepage = 'https://github.com/endorphin-studio/browser-detector'; |
||
31 | |||
32 | /** |
||
33 | * Composer package name |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $packageName = 'endorphin-studio/browser-detector'; |
||
38 | |||
39 | protected $detectionCapabilities = [ |
||
40 | |||
41 | 'browser' => [ |
||
42 | 'name' => true, |
||
43 | 'version' => true, |
||
44 | ], |
||
45 | |||
46 | 'renderingEngine' => [ |
||
47 | 'name' => false, |
||
48 | 'version' => false, |
||
49 | ], |
||
50 | |||
51 | 'operatingSystem' => [ |
||
52 | 'name' => true, |
||
53 | 'version' => true, |
||
54 | ], |
||
55 | |||
56 | 'device' => [ |
||
57 | 'model' => false, |
||
58 | 'brand' => false, |
||
59 | 'type' => true, |
||
60 | 'isMobile' => false, |
||
61 | 'isTouch' => false, |
||
62 | ], |
||
63 | |||
64 | 'bot' => [ |
||
65 | 'isBot' => true, |
||
66 | 'name' => true, |
||
67 | 'type' => true, |
||
68 | ], |
||
69 | ]; |
||
70 | |||
71 | protected $defaultValues = [ |
||
72 | |||
73 | 'general' => [ |
||
74 | '/^N\\\\A$/i', |
||
75 | ], |
||
76 | |||
77 | 'device' => [ |
||
78 | |||
79 | 'model' => [ |
||
80 | '/^Desktop/i', |
||
81 | ], |
||
82 | ], |
||
83 | ]; |
||
84 | |||
85 | /** |
||
86 | * Used for unitTests mocking |
||
87 | * |
||
88 | * @var EndorphinDetector\Detector |
||
89 | */ |
||
90 | private $parser; |
||
91 | |||
92 | /** |
||
93 | * |
||
94 | * @throws PackageNotLoadedException |
||
95 | */ |
||
96 | 14 | public function __construct() |
|
97 | { |
||
98 | 14 | $this->checkIfInstalled(); |
|
99 | 14 | } |
|
100 | |||
101 | /** |
||
102 | * |
||
103 | * @param string $userAgent |
||
104 | * @return EndorphinDetector\DetectorResult |
||
105 | */ |
||
106 | 7 | public function getParser($userAgent) |
|
107 | { |
||
108 | 7 | if ($this->parser !== null) { |
|
109 | 6 | return $this->parser; |
|
110 | } |
||
111 | |||
112 | 1 | return EndorphinDetector\Detector::analyse($userAgent); |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * |
||
117 | * @param EndorphinDetector\DetectorResult $resultRaw |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | 6 | private function hasResult(EndorphinDetector\DetectorResult $resultRaw) |
|
122 | { |
||
123 | 6 | if ($this->isRealResult($resultRaw->OS->getName()) === true) { |
|
124 | 1 | return true; |
|
125 | } |
||
126 | |||
127 | 5 | if ($this->isRealResult($resultRaw->Browser->getName()) === true) { |
|
128 | 1 | return true; |
|
129 | } |
||
130 | |||
131 | 4 | if ($this->isRealResult($resultRaw->Device->getName(), 'device', 'model') === true) { |
|
132 | 1 | return true; |
|
133 | } |
||
134 | |||
135 | 3 | if ($this->isRealResult($resultRaw->Robot->getType()) === true) { |
|
136 | 2 | return true; |
|
137 | } |
||
138 | |||
139 | 1 | return false; |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * |
||
144 | * @param Model\Bot $bot |
||
145 | * @param EndorphinDetector\Robot $resultRaw |
||
146 | */ |
||
147 | 2 | private function hydrateBot(Model\Bot $bot, EndorphinDetector\Robot $resultRaw) |
|
148 | { |
||
149 | 2 | $bot->setIsBot(true); |
|
150 | 2 | $bot->setName($this->getRealResult($resultRaw->getName())); |
|
151 | 2 | $bot->setType($this->getRealResult($resultRaw->getType())); |
|
152 | 2 | } |
|
153 | |||
154 | /** |
||
155 | * |
||
156 | * @param Model\Browser $browser |
||
157 | * @param EndorphinDetector\Browser $resultRaw |
||
158 | */ |
||
159 | 3 | private function hydrateBrowser(Model\Browser $browser, EndorphinDetector\Browser $resultRaw) |
|
160 | { |
||
161 | 3 | $browser->setName($this->getRealResult($resultRaw->getName())); |
|
162 | 3 | $browser->getVersion()->setComplete($this->getRealResult($resultRaw->getVersion())); |
|
163 | 3 | } |
|
164 | |||
165 | /** |
||
166 | * |
||
167 | * @param Model\OperatingSystem $os |
||
168 | * @param EndorphinDetector\OS $resultRaw |
||
169 | */ |
||
170 | 3 | private function hydrateOperatingSystem(Model\OperatingSystem $os, EndorphinDetector\OS $resultRaw) |
|
171 | { |
||
172 | 3 | $os->setName($this->getRealResult($resultRaw->getName())); |
|
173 | 3 | $os->getVersion()->setComplete($this->getRealResult($resultRaw->getVersion())); |
|
174 | 3 | } |
|
175 | |||
176 | /** |
||
177 | * |
||
178 | * @param Model\Device $device |
||
179 | * @param EndorphinDetector\Device $resultRaw |
||
180 | */ |
||
181 | 3 | private function hydrateDevice(Model\Device $device, EndorphinDetector\Device $resultRaw) |
|
182 | { |
||
183 | // $device->setModel($this->getRealResult($resultRaw->ModelName)); |
||
0 ignored issues
–
show
|
|||
184 | 3 | $device->setType($this->getRealResult($resultRaw->getType())); |
|
185 | 3 | } |
|
186 | |||
187 | 6 | public function parse($userAgent, array $headers = []) |
|
188 | { |
||
189 | 6 | $resultRaw = $this->getParser($userAgent); |
|
190 | |||
191 | /* |
||
192 | * No result found? |
||
193 | */ |
||
194 | 6 | if ($this->hasResult($resultRaw) !== true) { |
|
195 | 1 | throw new NoResultFoundException('No result found for user agent: ' . $userAgent); |
|
196 | } |
||
197 | |||
198 | /* |
||
199 | * Hydrate the model |
||
200 | */ |
||
201 | 5 | $result = new Model\UserAgent($this->getName(), $this->getVersion()); |
|
202 | 5 | $result->setProviderResultRaw($resultRaw); |
|
203 | |||
204 | /* |
||
205 | * Bot detection |
||
206 | */ |
||
207 | 5 | if ($this->isRealResult($resultRaw->Robot->getType()) === true) { |
|
208 | 2 | $this->hydrateBot($result->getBot(), $resultRaw->Robot); |
|
209 | |||
210 | 2 | return $result; |
|
211 | } |
||
212 | |||
213 | /* |
||
214 | * hydrate the result |
||
215 | */ |
||
216 | 3 | if ($resultRaw->Browser instanceof EndorphinDetector\Browser) { |
|
217 | 3 | $this->hydrateBrowser($result->getBrowser(), $resultRaw->Browser); |
|
218 | } |
||
219 | 3 | if ($resultRaw->OS instanceof EndorphinDetector\OS) { |
|
220 | 3 | $this->hydrateOperatingSystem($result->getOperatingSystem(), $resultRaw->OS); |
|
221 | } |
||
222 | 3 | if ($resultRaw->Device instanceof EndorphinDetector\Device) { |
|
223 | 3 | $this->hydrateDevice($result->getDevice(), $resultRaw->Device); |
|
224 | } |
||
225 | |||
226 | 3 | return $result; |
|
227 | } |
||
228 | } |
||
229 |
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.