Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
13 | class UserAgentStringCom extends AbstractHttpProvider |
||
14 | { |
||
15 | protected $detectionCapabilities = [ |
||
16 | |||
17 | 'browser' => [ |
||
18 | 'name' => true, |
||
19 | 'version' => true, |
||
20 | ], |
||
21 | |||
22 | 'renderingEngine' => [ |
||
23 | 'name' => false, |
||
24 | 'version' => false, |
||
25 | ], |
||
26 | |||
27 | 'operatingSystem' => [ |
||
28 | 'name' => true, |
||
29 | 'version' => true, |
||
30 | ], |
||
31 | |||
32 | 'device' => [ |
||
33 | 'model' => false, |
||
34 | 'brand' => false, |
||
35 | 'type' => false, |
||
36 | 'isMobile' => false, |
||
37 | 'isTouch' => false, |
||
38 | ], |
||
39 | |||
40 | 'bot' => [ |
||
41 | 'isBot' => true, |
||
42 | 'name' => true, |
||
43 | 'type' => true, |
||
44 | ], |
||
45 | ]; |
||
46 | |||
47 | protected $defaultValues = [ |
||
48 | 'Null', |
||
49 | 'unknown', |
||
50 | ]; |
||
51 | |||
52 | private $botTypes = [ |
||
53 | 'Crawler', |
||
54 | 'Cloud Platform', |
||
55 | 'Feed Reader', |
||
56 | 'LinkChecker', |
||
57 | 'Validator', |
||
58 | ]; |
||
59 | |||
60 | private static $uri = 'http://www.useragentstring.com/'; |
||
61 | |||
62 | 1 | public function getName() |
|
66 | |||
67 | 1 | public function getComposerPackageName() |
|
71 | |||
72 | 1 | public function getVersion() |
|
76 | |||
77 | /** |
||
78 | * |
||
79 | * @param string $userAgent |
||
80 | * @param array $headers |
||
81 | * @return stdClass |
||
82 | * @throws Exception\RequestException |
||
83 | */ |
||
84 | 7 | protected function getResult($userAgent, array $headers) |
|
118 | |||
119 | /** |
||
120 | * |
||
121 | * @param stdClass $resultRaw |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 4 | View Code Duplication | private function hasResult(stdClass $resultRaw) |
133 | |||
134 | /** |
||
135 | * |
||
136 | * @param stdClass $resultRaw |
||
137 | * @return boolean |
||
138 | */ |
||
139 | 3 | private function isBot(stdClass $resultRaw) |
|
147 | |||
148 | /** |
||
149 | * |
||
150 | * @param Model\Bot $bot |
||
151 | * @param stdClass $resultRaw |
||
152 | */ |
||
153 | 1 | private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) |
|
165 | |||
166 | /** |
||
167 | * |
||
168 | * @param Model\Browser $browser |
||
169 | * @param stdClass $resultRaw |
||
170 | */ |
||
171 | 2 | View Code Duplication | private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) |
181 | |||
182 | /** |
||
183 | * |
||
184 | * @param Model\OperatingSystem $os |
||
185 | * @param stdClass $resultRaw |
||
186 | */ |
||
187 | 2 | private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) |
|
197 | |||
198 | 7 | View Code Duplication | public function parse($userAgent, array $headers = []) |
232 | } |
||
233 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.