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 |
||
| 25 | class EngineFinder extends AbstractFinder |
||
| 26 | { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Find a result based on a specific criteria. |
||
| 30 | * |
||
| 31 | * @since 0.1.0 |
||
| 32 | * |
||
| 33 | * @param array $criteria Criteria to search for. |
||
| 34 | * |
||
| 35 | * @return mixed Result of the search. |
||
|
|
|||
| 36 | */ |
||
| 37 | 17 | public function find(array $criteria) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Initialize the engines that can be iterated. |
||
| 54 | * |
||
| 55 | * @since 0.1.0 |
||
| 56 | * |
||
| 57 | */ |
||
| 58 | 17 | View Code Duplication | protected function initializeEngines() |
| 68 | |||
| 69 | /** |
||
| 70 | * Initialize a single engine by instantiating class name strings and calling closures. |
||
| 71 | * |
||
| 72 | * @since 0.1.0 |
||
| 73 | * |
||
| 74 | * @param mixed $engine Engine to instantiate. |
||
| 75 | * |
||
| 76 | * @return EngineInterface Instantiated engine. |
||
| 77 | * @throws FailedToInstantiateEngineException If the engine could not be instantiated. |
||
| 78 | */ |
||
| 79 | 17 | protected function initializeEngine($engine) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Get the config key for the Findables definitions. |
||
| 103 | * |
||
| 104 | * @since 0.1.0 |
||
| 105 | * |
||
| 106 | * @return string Config key use to define the Findables. |
||
| 107 | */ |
||
| 108 | 7 | protected function getFindablesConfigKey() |
|
| 112 | } |
||
| 113 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.