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 |
||
13 | View Code Duplication | class PhpMdToolHandler implements CommandHandlerInterface |
|
|
|||
14 | { |
||
15 | const CHECKING_MESSAGE = 'Checking code mess with PHPMD'; |
||
16 | /** |
||
17 | * @var OutputInterface |
||
18 | */ |
||
19 | private $output; |
||
20 | /** |
||
21 | * @var PhpMdToolProcessorInterface |
||
22 | */ |
||
23 | private $phpMdToolProcessor; |
||
24 | |||
25 | /** |
||
26 | * PhpMdTool constructor. |
||
27 | * |
||
28 | * @param OutputInterface $output |
||
29 | * @param PhpMdToolProcessorInterface $phpMdToolProcessor |
||
30 | */ |
||
31 | 2 | public function __construct(OutputInterface $output, PhpMdToolProcessorInterface $phpMdToolProcessor) |
|
36 | |||
37 | /** |
||
38 | * @param array $files |
||
39 | * @param string $options |
||
40 | * @param string $errorMessage |
||
41 | * |
||
42 | * @throws PhpMdViolationsException |
||
43 | */ |
||
44 | 2 | private function execute(array $files, $options, $errorMessage) |
|
66 | |||
67 | /** |
||
68 | * @param CommandInterface|PhpMdTool $command |
||
69 | */ |
||
70 | 2 | public function handle(CommandInterface $command) |
|
74 | } |
||
75 |
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.