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 |
||
| 24 | class Detector |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var array Array of options |
||
| 28 | */ |
||
| 29 | protected $options = [ |
||
| 30 | 'dataProvider' => '\\EndorphinStudio\\Detector\\Storage\\YamlStorage', |
||
| 31 | 'dataDirectory' => 'auto', |
||
| 32 | 'cacheDirectory' => 'auto', |
||
| 33 | 'format' => 'yaml' |
||
| 34 | ]; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var StorageInterface |
||
| 38 | */ |
||
| 39 | private $dataProvider; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get storage provider |
||
| 43 | * @return StorageInterface |
||
| 44 | */ |
||
| 45 | public function getDataProvider(): StorageInterface |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Get result object |
||
| 52 | * @return Result Result object |
||
| 53 | */ |
||
| 54 | public function getResultObject(): Result |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var Result Result object |
||
| 61 | */ |
||
| 62 | private $resultObject; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set data provider |
||
| 66 | * @param StorageInterface $dataProvider |
||
| 67 | */ |
||
| 68 | public function setDataProvider(StorageInterface $dataProvider) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return mixed |
||
| 75 | */ |
||
| 76 | public function getUserAgent() |
||
| 80 | |||
| 81 | private $ua; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var array |
||
| 85 | */ |
||
| 86 | private $detectors; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Detector constructor. |
||
| 90 | * Options: |
||
| 91 | * 'dataProvider' => '\\EndorphinStudio\\Detector\\Storage\\YamlStorage', |
||
| 92 | * 'dataDirectory' => 'auto', |
||
| 93 | * 'cacheDirectory' => 'auto', |
||
| 94 | * 'format' => 'yaml' |
||
| 95 | * @param array $options Array of options |
||
| 96 | * @throws \ReflectionException |
||
| 97 | * @throws StorageException |
||
| 98 | */ |
||
| 99 | public function __construct(array $options = []) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Analyse User Agent String |
||
| 118 | * @param string $ua |
||
| 119 | * @return Result |
||
| 120 | */ |
||
| 121 | public function analyse(string $ua = 'ua'): Result |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Get list of patterns from config |
||
| 134 | * @param $list |
||
| 135 | * @param $type |
||
| 136 | * @return array |
||
| 137 | */ |
||
| 138 | public function getPatternList($list, $type) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Initialisation method |
||
| 145 | * @throws \ReflectionException |
||
| 146 | * @throws StorageException |
||
| 147 | */ |
||
| 148 | protected function init() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return string |
||
| 165 | * @throws StorageException |
||
| 166 | * @throws \ReflectionException |
||
| 167 | */ |
||
| 168 | View Code Duplication | private function findDataDirectory(): string |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @return string |
||
| 183 | * @throws StorageException |
||
| 184 | * @throws \ReflectionException |
||
| 185 | */ |
||
| 186 | View Code Duplication | private function findCacheDirectory(): string |
|
| 198 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.