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 PhpTalLint extends Plugin |
||
| 16 | { |
||
| 17 | protected $recursive = true; |
||
| 18 | protected $suffixes; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return string |
||
| 22 | */ |
||
| 23 | public static function pluginName() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string The path to a file contain custom phptal_tales_ functions |
||
| 30 | */ |
||
| 31 | protected $tales; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | protected $allowedWarnings; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | protected $allowedErrors; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var array The results of the lint scan |
||
| 45 | */ |
||
| 46 | protected $failedPaths = []; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function __construct(Builder $builder, Build $build, array $options = []) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Executes phptal lint |
||
| 67 | */ |
||
| 68 | public function execute() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Lint an item (file or directory) by calling the appropriate method. |
||
| 102 | * |
||
| 103 | * @param $item |
||
| 104 | * @param $itemPath |
||
| 105 | * @return bool |
||
| 106 | */ |
||
| 107 | protected function lintItem($item, $itemPath) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Run phptal lint against a directory of files. |
||
| 124 | * |
||
| 125 | * @param $path |
||
| 126 | * @return bool |
||
| 127 | */ |
||
| 128 | View Code Duplication | protected function lintDirectory($path) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Run phptal lint against a specific file. |
||
| 154 | * |
||
| 155 | * @param $path |
||
| 156 | * @return bool |
||
| 157 | */ |
||
| 158 | protected function lintFile($path) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Process options and produce an arguments string for PHPTAL Lint. |
||
| 208 | * |
||
| 209 | * @return array |
||
| 210 | */ |
||
| 211 | protected function getFlags() |
||
| 225 | } |
||
| 226 |
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.