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 | /** |
||
| 16 | * Name of the provider |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $name = 'UserAgentStringCom'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Homepage of the provider |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $homepage = 'http://www.useragentstring.com/'; |
||
| 28 | |||
| 29 | protected $detectionCapabilities = [ |
||
| 30 | |||
| 31 | 'browser' => [ |
||
| 32 | 'name' => true, |
||
| 33 | 'version' => true, |
||
| 34 | ], |
||
| 35 | |||
| 36 | 'renderingEngine' => [ |
||
| 37 | 'name' => false, |
||
| 38 | 'version' => false, |
||
| 39 | ], |
||
| 40 | |||
| 41 | 'operatingSystem' => [ |
||
| 42 | 'name' => true, |
||
| 43 | 'version' => true, |
||
| 44 | ], |
||
| 45 | |||
| 46 | 'device' => [ |
||
| 47 | 'model' => false, |
||
| 48 | 'brand' => false, |
||
| 49 | 'type' => false, |
||
| 50 | 'isMobile' => false, |
||
| 51 | 'isTouch' => false, |
||
| 52 | ], |
||
| 53 | |||
| 54 | 'bot' => [ |
||
| 55 | 'isBot' => true, |
||
| 56 | 'name' => true, |
||
| 57 | 'type' => true, |
||
| 58 | ], |
||
| 59 | ]; |
||
| 60 | |||
| 61 | protected $defaultValues = [ |
||
| 62 | 'Null', |
||
| 63 | 'unknown', |
||
| 64 | ]; |
||
| 65 | |||
| 66 | private $botTypes = [ |
||
| 67 | 'Crawler', |
||
| 68 | 'Cloud Platform', |
||
| 69 | 'Feed Reader', |
||
| 70 | 'LinkChecker', |
||
| 71 | 'Validator', |
||
| 72 | ]; |
||
| 73 | |||
| 74 | private static $uri = 'http://www.useragentstring.com/'; |
||
| 75 | |||
| 76 | 1 | public function getVersion() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * |
||
| 83 | * @param string $userAgent |
||
| 84 | * @param array $headers |
||
| 85 | * @return stdClass |
||
| 86 | * @throws Exception\RequestException |
||
| 87 | */ |
||
| 88 | 7 | protected function getResult($userAgent, array $headers) |
|
| 122 | |||
| 123 | /** |
||
| 124 | * |
||
| 125 | * @param stdClass $resultRaw |
||
| 126 | * |
||
| 127 | * @return bool |
||
| 128 | */ |
||
| 129 | 4 | View Code Duplication | private function hasResult(stdClass $resultRaw) |
| 137 | |||
| 138 | /** |
||
| 139 | * |
||
| 140 | * @param stdClass $resultRaw |
||
| 141 | * @return boolean |
||
| 142 | */ |
||
| 143 | 3 | private function isBot(stdClass $resultRaw) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * |
||
| 154 | * @param Model\Bot $bot |
||
| 155 | * @param stdClass $resultRaw |
||
| 156 | */ |
||
| 157 | 1 | private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * |
||
| 172 | * @param Model\Browser $browser |
||
| 173 | * @param stdClass $resultRaw |
||
| 174 | */ |
||
| 175 | 2 | View Code Duplication | private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) |
| 185 | |||
| 186 | /** |
||
| 187 | * |
||
| 188 | * @param Model\OperatingSystem $os |
||
| 189 | * @param stdClass $resultRaw |
||
| 190 | */ |
||
| 191 | 2 | private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) |
|
| 201 | |||
| 202 | 7 | View Code Duplication | public function parse($userAgent, array $headers = []) |
| 236 | } |
||
| 237 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.