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 |
||
| 15 | class UdgerCom extends AbstractHttpProvider |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Name of the provider |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $name = 'UdgerCom'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Homepage of the provider |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $homepage = 'https://udger.com/'; |
||
| 30 | |||
| 31 | protected $detectionCapabilities = [ |
||
| 32 | |||
| 33 | 'browser' => [ |
||
| 34 | 'name' => true, |
||
| 35 | 'version' => true, |
||
| 36 | ], |
||
| 37 | |||
| 38 | 'renderingEngine' => [ |
||
| 39 | 'name' => true, |
||
| 40 | 'version' => false, |
||
| 41 | ], |
||
| 42 | |||
| 43 | 'operatingSystem' => [ |
||
| 44 | 'name' => true, |
||
| 45 | 'version' => false, |
||
| 46 | ], |
||
| 47 | |||
| 48 | 'device' => [ |
||
| 49 | 'model' => false, |
||
| 50 | 'brand' => false, |
||
| 51 | 'type' => true, |
||
| 52 | 'isMobile' => false, |
||
| 53 | 'isTouch' => false, |
||
| 54 | ], |
||
| 55 | |||
| 56 | 'bot' => [ |
||
| 57 | 'isBot' => true, |
||
| 58 | 'name' => false, |
||
| 59 | 'type' => false, |
||
| 60 | ], |
||
| 61 | ]; |
||
| 62 | |||
| 63 | protected $defaultValues = [ |
||
| 64 | 'unknown', |
||
| 65 | ]; |
||
| 66 | |||
| 67 | private static $uri = 'http://api.udger.com/parse'; |
||
| 68 | |||
| 69 | private $apiKey; |
||
| 70 | |||
| 71 | 17 | public function __construct(Client $client, $apiKey) |
|
| 77 | |||
| 78 | 1 | public function getVersion() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * |
||
| 85 | * @param string $userAgent |
||
| 86 | * @param array $headers |
||
| 87 | * @return stdClass |
||
| 88 | * @throws Exception\RequestException |
||
| 89 | */ |
||
| 90 | 12 | protected function getResult($userAgent, array $headers) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * |
||
| 163 | * @param stdClass $resultRaw |
||
| 164 | * @return boolean |
||
| 165 | */ |
||
| 166 | 5 | View Code Duplication | private function isBot(stdClass $resultRaw) |
| 174 | |||
| 175 | /** |
||
| 176 | * |
||
| 177 | * @param Model\Bot $bot |
||
| 178 | * @param stdClass $resultRaw |
||
| 179 | */ |
||
| 180 | 1 | View Code Duplication | private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) |
| 188 | |||
| 189 | /** |
||
| 190 | * |
||
| 191 | * @param Model\Browser $browser |
||
| 192 | * @param stdClass $resultRaw |
||
| 193 | */ |
||
| 194 | 4 | private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) |
|
| 204 | |||
| 205 | /** |
||
| 206 | * |
||
| 207 | * @param Model\RenderingEngine $engine |
||
| 208 | * @param stdClass $resultRaw |
||
| 209 | */ |
||
| 210 | 4 | private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * |
||
| 219 | * @param Model\OperatingSystem $os |
||
| 220 | * @param stdClass $resultRaw |
||
| 221 | */ |
||
| 222 | 4 | private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * |
||
| 231 | * @param Model\UserAgent $device |
||
| 232 | * @param stdClass $resultRaw |
||
| 233 | */ |
||
| 234 | 4 | private function hydrateDevice(Model\Device $device, stdClass $resultRaw) |
|
| 240 | |||
| 241 | 12 | public function parse($userAgent, array $headers = []) |
|
| 270 | } |
||
| 271 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.