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 PhpMDHandler extends ToolHandler implements RecursiveToolInterface |
||
16 | { |
||
17 | /** @var array */ |
||
18 | private $files; |
||
19 | /** @var string */ |
||
20 | private $needle; |
||
21 | /** |
||
22 | * @var IgnoreFiles |
||
23 | */ |
||
24 | private $ignoreFiles; |
||
25 | |||
26 | /** |
||
27 | * PhpMDHandler constructor. |
||
28 | * |
||
29 | * @param OutputHandlerInterface $outputHandler |
||
30 | * @param IgnoreFiles $ignoreFiles |
||
31 | */ |
||
32 | public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles) |
||
37 | |||
38 | /** |
||
39 | * @param array $messages |
||
40 | * |
||
41 | * @throws PHPMDViolationsException |
||
42 | */ |
||
43 | public function run(array $messages) |
||
89 | |||
90 | /** |
||
91 | * @param string $needle |
||
92 | */ |
||
93 | public function setNeedle($needle) |
||
97 | |||
98 | /** |
||
99 | * @param array $files |
||
100 | */ |
||
101 | public function setFiles($files) |
||
105 | } |
||
106 |
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.