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 | private $version = '4.0.5'; |
||
| 27 | |||
| 28 | public function getVersion(): string |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array Array of options |
||
| 35 | */ |
||
| 36 | protected $options = [ |
||
| 37 | 'dataProvider' => '\\EndorphinStudio\\Detector\\Storage\\YamlStorage', |
||
| 38 | 'dataDirectory' => 'auto', |
||
| 39 | 'cacheDirectory' => 'auto', |
||
| 40 | 'format' => 'yaml' |
||
| 41 | ]; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var StorageInterface |
||
| 45 | */ |
||
| 46 | private $dataProvider; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get storage provider |
||
| 50 | * @return StorageInterface |
||
| 51 | */ |
||
| 52 | public function getDataProvider(): StorageInterface |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get result object |
||
| 59 | * @return Result Result object |
||
| 60 | */ |
||
| 61 | public function getResultObject(): Result |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var Result Result object |
||
| 68 | */ |
||
| 69 | private $resultObject; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Set data provider |
||
| 73 | * @param StorageInterface $dataProvider |
||
| 74 | */ |
||
| 75 | public function setDataProvider(StorageInterface $dataProvider) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @return mixed |
||
| 82 | */ |
||
| 83 | public function getUserAgent() |
||
| 87 | |||
| 88 | private $ua; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var array |
||
| 92 | */ |
||
| 93 | private $detectors; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Detector constructor. |
||
| 97 | * Options: |
||
| 98 | * 'dataProvider' => '\\EndorphinStudio\\Detector\\Storage\\YamlStorage', |
||
| 99 | * 'dataDirectory' => 'auto', |
||
| 100 | * 'cacheDirectory' => 'auto', |
||
| 101 | * 'format' => 'yaml' |
||
| 102 | * @param array $options Array of options |
||
| 103 | * @throws \ReflectionException |
||
| 104 | * @throws StorageException |
||
| 105 | */ |
||
| 106 | public function __construct(array $options = []) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Analyse User Agent String |
||
| 125 | * @param string $ua |
||
| 126 | * @return Result |
||
| 127 | */ |
||
| 128 | public function analyse(string $ua = 'ua'): Result |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Get list of patterns from config |
||
| 141 | * @param $list |
||
| 142 | * @param $type |
||
| 143 | * @return array |
||
| 144 | */ |
||
| 145 | public function getPatternList($list, $type) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Initialisation method |
||
| 152 | * @throws \ReflectionException |
||
| 153 | * @throws StorageException |
||
| 154 | */ |
||
| 155 | protected function init() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return string |
||
| 172 | * @throws StorageException |
||
| 173 | * @throws \ReflectionException |
||
| 174 | */ |
||
| 175 | View Code Duplication | private function findDataDirectory(): string |
|
| 187 | |||
| 188 | /** |
||
| 189 | * @return string |
||
| 190 | * @throws StorageException |
||
| 191 | * @throws \ReflectionException |
||
| 192 | */ |
||
| 193 | View Code Duplication | private function findCacheDirectory(): string |
|
| 205 | } |
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.