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 |
||
| 42 | class ProposedOkFilenameLoader extends FilteredLoader implements FilteredLoaderInterface, SortedLoaderInterface |
||
| 43 | { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The regular expression used to load the files with. |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | private $regex = '/^.*\/%s\\.%s$/'; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The actual source directory to use. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $sourceDir; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The file resolver configuration instance. |
||
| 61 | * |
||
| 62 | * @var \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface |
||
| 63 | */ |
||
| 64 | private $fileResolverConfiguration; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The sorter instance to use. |
||
| 68 | * |
||
| 69 | * @var \TechDivision\Import\Loaders\Sorters\SorterImplInterface |
||
| 70 | */ |
||
| 71 | private $sorterImpl; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Initializes the file handler instance. |
||
| 75 | * |
||
| 76 | * @param \TechDivision\Import\Loaders\FilteredLoaderInterface $loader The parent loader instance |
||
| 77 | * @param \TechDivision\Import\Loaders\Filters\FilterImplInterface $filterImpl The filter instance to use |
||
| 78 | * @param \TechDivision\Import\Loaders\Sorters\SorterImplInterface $sorterImpl The sorter instance to use |
||
| 79 | */ |
||
| 80 | public function __construct( |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Returns the file resolver configuration instance. |
||
| 95 | * |
||
| 96 | * @return \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface The configuration instance |
||
| 97 | */ |
||
| 98 | protected function getFileResolverConfiguration() : FileResolverConfigurationInterface |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Return's the sorter instance to use. |
||
| 105 | * |
||
| 106 | * @return \TechDivision\Import\Loaders\Sorters\SorterImplInterface The sorter instance to use |
||
| 107 | */ |
||
| 108 | protected function getSorterImpl() : SorterImplInterface |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Returns the regular expression used to load the files with. |
||
| 115 | * |
||
| 116 | * @return string The regular expression |
||
| 117 | */ |
||
| 118 | protected function getRegex() : string |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Remove's the passed line from the file with the passed name. |
||
| 125 | * |
||
| 126 | * @param string $line The line to be removed |
||
| 127 | * @param string $filename The name of the file the line has to be removed |
||
| 128 | * |
||
| 129 | * @return void |
||
| 130 | * @throws \Exception Is thrown, if the file doesn't exists, the line is not found or can not be removed |
||
| 131 | */ |
||
| 132 | protected function removeLineFromFile(string $line, string $filename) : void |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Query whether or not the basename, without suffix, of the passed filenames are equal. |
||
| 139 | * |
||
| 140 | * @param string $filename1 The first filename to compare |
||
| 141 | * @param string $filename2 The second filename to compare |
||
| 142 | * |
||
| 143 | * @return boolean TRUE if the passed files basename are equal, else FALSE |
||
| 144 | * @todo Refactorig required, because of duplicate method |
||
| 145 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::isEqualFilename() |
||
| 146 | */ |
||
| 147 | protected function isEqualFilename(string $filename1, string $filename2) : bool |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Strips the passed suffix, including the (.), from the filename and returns it. |
||
| 154 | * |
||
| 155 | * @param string $filename The filename to return the suffix from |
||
| 156 | * @param string $suffix The suffix to return |
||
| 157 | * |
||
| 158 | * @return string The filname without the suffix |
||
| 159 | * @todo Refactorig required, because of duplicate method |
||
| 160 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::stripSuffix() |
||
| 161 | */ |
||
| 162 | protected function stripSuffix(string $filename, string $suffix) : string |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Prepares and returns an OK filename from the passed parts. |
||
| 169 | * |
||
| 170 | * @param array $parts The parts to concatenate the OK filename from |
||
| 171 | * |
||
| 172 | * @return string The OK filename |
||
| 173 | * @todo Refactorig required, because of duplicate method |
||
| 174 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::prepareOkFilename() |
||
| 175 | */ |
||
| 176 | protected function prepareOkFilename(array $parts) : string |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Returns the delement separator char. |
||
| 183 | * |
||
| 184 | * @return string The element separator char |
||
| 185 | */ |
||
| 186 | protected function getElementSeparator() : string |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Returns the elements the filenames consists of. |
||
| 193 | * |
||
| 194 | * @return array The array with the filename elements |
||
| 195 | * @todo Refactorig required, because of duplicate method |
||
| 196 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::getPatternElements() |
||
| 197 | */ |
||
| 198 | protected function getPatternElements() : array |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Returns the suffix for the import files. |
||
| 205 | * |
||
| 206 | * @return string The suffix |
||
| 207 | */ |
||
| 208 | protected function getSuffix() : string |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Returns the elements the filenames consists of. |
||
| 215 | * |
||
| 216 | * @return array The array with the filename elements |
||
| 217 | * @todo Refactorig required, because of duplicate method |
||
| 218 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::getOkFileSuffix() |
||
| 219 | */ |
||
| 220 | protected function getOkFileSuffix() : string |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Returns the actual source directory to load the files from. |
||
| 227 | * |
||
| 228 | * @return string The actual source directory |
||
| 229 | */ |
||
| 230 | protected function getSourceDir() : string |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Returns the elements the filenames consists of, converted to lowercase. |
||
| 237 | * |
||
| 238 | * @return array The array with the filename elements |
||
| 239 | * @todo Refactorig required, because of duplicate method |
||
| 240 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::getPatternKeys() |
||
| 241 | */ |
||
| 242 | protected function getPatternKeys() : array |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Resolves the pattern value for the given element name. |
||
| 259 | * |
||
| 260 | * @param string $element The element name to resolve the pattern value for |
||
| 261 | * |
||
| 262 | * @return string The resolved pattern value |
||
| 263 | * @throws \InvalidArgumentException Is thrown, if the element value can not be loaded from the file resolver configuration |
||
| 264 | * @todo Refactorig required, because of duplicate method |
||
| 265 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::resolvePatternValue() |
||
| 266 | */ |
||
| 267 | View Code Duplication | protected function resolvePatternValue(string $element) : string |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Returns the values to create the regex pattern from. |
||
| 290 | * |
||
| 291 | * @return array The array with the pattern values |
||
| 292 | * @todo Refactorig required, because of duplicate method |
||
| 293 | * @see \TechDivision\Import\Loaders\Filters\OkFileFilter::resolvePatternValues() |
||
| 294 | */ |
||
| 295 | View Code Duplication | protected function resolvePatternValues() : array |
|
| 309 | |||
| 310 | /** |
||
| 311 | * Prepares and returns the pattern for the regex to load the files from the |
||
| 312 | * source directory for the passed subject. |
||
| 313 | * |
||
| 314 | * @return string The prepared regex pattern |
||
| 315 | */ |
||
| 316 | protected function getPattern() : string |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Returns the match with the passed name. |
||
| 327 | * |
||
| 328 | * @param array $keys The keys of the match to return |
||
| 329 | * |
||
| 330 | * @return string|null The match itself |
||
| 331 | */ |
||
| 332 | protected function proposedOkFilenamesByKeys(array $keys) : array |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Return's an array with the proposed .OK filenames as key and the matching CSV |
||
| 371 | * files as values for the import with the passed serial. |
||
| 372 | * |
||
| 373 | * Based on the passed serial, the files with the configured prefix from the also |
||
| 374 | * configured source directory will be loaded and processed to return the array |
||
| 375 | * with the proposed .OK filenames. |
||
| 376 | * |
||
| 377 | * @return array The array with key => value pairs of the proposed .OK and the matching CSV files |
||
| 378 | */ |
||
| 379 | protected function propsedOkFilenames() : array |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Return's the actual source directory. |
||
| 408 | * |
||
| 409 | * @param string $sourceDir The actual source directory |
||
| 410 | * |
||
| 411 | * @return void |
||
| 412 | */ |
||
| 413 | public function setSourceDir(string $sourceDir) : void |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Add's the passed sorter to the loader instance. |
||
| 420 | * |
||
| 421 | * @param callable $sorter The sorter to add |
||
| 422 | * |
||
| 423 | * @return void |
||
| 424 | */ |
||
| 425 | public function addSorter(callable $sorter) : void |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Return's the array with the sorter callbacks. |
||
| 432 | * |
||
| 433 | * @return callable[] The sorter callbacks |
||
| 434 | */ |
||
| 435 | public function getSorters() : array |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Set's the file resolver configuration. |
||
| 442 | * |
||
| 443 | * @param \TechDivision\Import\Configuration\Subject\FileResolverConfigurationInterface $fileResolverConfiguration The file resolver configuration |
||
| 444 | * |
||
| 445 | * @return void |
||
| 446 | */ |
||
| 447 | public function setFileResolverConfiguration(FileResolverConfigurationInterface $fileResolverConfiguration) : void |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Loads, sorts and returns the files by using the passed glob pattern. |
||
| 454 | * |
||
| 455 | * If no pattern will be passed to the `load()` method, the files of |
||
| 456 | * the actual directory using `getcwd()` will be returned. |
||
| 457 | * |
||
| 458 | * @param string|null $pattern The pattern to load the files from the filesystem |
||
| 459 | * |
||
| 460 | * @return array The array with the data |
||
| 461 | */ |
||
| 462 | public function load(string $pattern = null) : array |
||
| 500 | } |
||
| 501 |
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.