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 UserAgentApiCom extends AbstractHttpProvider |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Name of the provider |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $name = 'UserAgentApiCom'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Homepage of the provider |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $homepage = 'http://useragentapi.com/'; |
||
| 30 | |||
| 31 | protected $detectionCapabilities = [ |
||
| 32 | |||
| 33 | 'browser' => [ |
||
| 34 | 'name' => true, |
||
| 35 | 'version' => true, |
||
| 36 | ], |
||
| 37 | |||
| 38 | 'renderingEngine' => [ |
||
| 39 | 'name' => true, |
||
| 40 | 'version' => true, |
||
| 41 | ], |
||
| 42 | |||
| 43 | 'operatingSystem' => [ |
||
| 44 | 'name' => false, |
||
| 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' => true, |
||
| 59 | 'type' => false, |
||
| 60 | ], |
||
| 61 | ]; |
||
| 62 | |||
| 63 | private static $uri = 'https://useragentapi.com/api/v3/json'; |
||
| 64 | |||
| 65 | private $apiKey; |
||
| 66 | |||
| 67 | 16 | public function __construct(Client $client, $apiKey) |
|
| 73 | |||
| 74 | 1 | public function getVersion() |
|
| 78 | |||
| 79 | /** |
||
| 80 | * |
||
| 81 | * @param string $userAgent |
||
| 82 | * @param array $headers |
||
| 83 | * @return stdClass |
||
| 84 | * @throws Exception\RequestException |
||
| 85 | */ |
||
| 86 | 11 | protected function getResult($userAgent, array $headers) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * |
||
| 158 | * @param stdClass $resultRaw |
||
| 159 | * @return boolean |
||
| 160 | */ |
||
| 161 | 4 | private function isBot(stdClass $resultRaw) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * |
||
| 172 | * @param Model\Bot $bot |
||
| 173 | * @param stdClass $resultRaw |
||
| 174 | */ |
||
| 175 | 1 | View Code Duplication | private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) |
| 183 | |||
| 184 | /** |
||
| 185 | * |
||
| 186 | * @param Model\Browser $browser |
||
| 187 | * @param stdClass $resultRaw |
||
| 188 | */ |
||
| 189 | 3 | private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * |
||
| 202 | * @param Model\RenderingEngine $engine |
||
| 203 | * @param stdClass $resultRaw |
||
| 204 | */ |
||
| 205 | 3 | private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) |
|
| 215 | |||
| 216 | /** |
||
| 217 | * |
||
| 218 | * @param Model\UserAgent $device |
||
| 219 | * @param stdClass $resultRaw |
||
| 220 | */ |
||
| 221 | 3 | private function hydrateDevice(Model\Device $device, stdClass $resultRaw) |
|
| 227 | |||
| 228 | 11 | public function parse($userAgent, array $headers = []) |
|
| 256 | } |
||
| 257 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.