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 | 18 | public function __construct(Client $client, $apiKey) |
|
| 72 | { |
||
| 73 | 18 | parent::__construct($client); |
|
| 74 | |||
| 75 | 18 | $this->apiKey = $apiKey; |
|
| 76 | 18 | } |
|
| 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 | 13 | protected function getResult($userAgent, array $headers) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * |
||
| 156 | * @param stdClass $resultRaw |
||
| 157 | * @return boolean |
||
| 158 | */ |
||
| 159 | 5 | View Code Duplication | private function isBot(stdClass $resultRaw) |
| 167 | |||
| 168 | /** |
||
| 169 | * |
||
| 170 | * @param Model\Bot $bot |
||
| 171 | * @param stdClass $resultRaw |
||
| 172 | */ |
||
| 173 | 1 | View Code Duplication | private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) |
| 181 | |||
| 182 | /** |
||
| 183 | * |
||
| 184 | * @param Model\Browser $browser |
||
| 185 | * @param stdClass $resultRaw |
||
| 186 | */ |
||
| 187 | 4 | private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) |
|
| 197 | |||
| 198 | /** |
||
| 199 | * |
||
| 200 | * @param Model\RenderingEngine $engine |
||
| 201 | * @param stdClass $resultRaw |
||
| 202 | */ |
||
| 203 | 4 | private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass $resultRaw) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * |
||
| 212 | * @param Model\OperatingSystem $os |
||
| 213 | * @param stdClass $resultRaw |
||
| 214 | */ |
||
| 215 | 4 | private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) |
|
| 221 | |||
| 222 | /** |
||
| 223 | * |
||
| 224 | * @param Model\UserAgent $device |
||
| 225 | * @param stdClass $resultRaw |
||
| 226 | */ |
||
| 227 | 4 | private function hydrateDevice(Model\Device $device, stdClass $resultRaw) |
|
| 233 | |||
| 234 | 13 | public function parse($userAgent, array $headers = []) |
|
| 263 | } |
||
| 264 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.