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 |
||
| 15 | class Lint extends Plugin |
||
| 16 | { |
||
| 17 | protected $directories; |
||
| 18 | protected $recursive = true; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return string |
||
| 22 | */ |
||
| 23 | public static function pluginName() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function __construct(Builder $builder, Build $build, array $options = []) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Executes parallel lint |
||
| 59 | */ |
||
| 60 | public function execute() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Lint an item (file or directory) by calling the appropriate method. |
||
| 77 | * |
||
| 78 | * @param $php |
||
| 79 | * @param $item |
||
| 80 | * @param $itemPath |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | protected function lintItem($php, $item, $itemPath) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Run php -l against a directory of files. |
||
| 101 | * |
||
| 102 | * @param $php |
||
| 103 | * @param $path |
||
| 104 | * @return bool |
||
| 105 | */ |
||
| 106 | View Code Duplication | protected function lintDirectory($php, $path) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Run php -l against a specific file. |
||
| 132 | * |
||
| 133 | * @param $php |
||
| 134 | * @param $path |
||
| 135 | * @return bool |
||
| 136 | */ |
||
| 137 | protected function lintFile($php, $path) |
||
| 148 | } |
||
| 149 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.