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 PhpCsToolHandler implements CommandHandlerInterface |
|
|
|||
14 | { |
||
15 | const EXECUTE_MESSAGE = 'Checking code style with PHPCS'; |
||
16 | /** |
||
17 | * @var OutputInterface |
||
18 | */ |
||
19 | private $output; |
||
20 | /** |
||
21 | * @var PhpCsToolProcessorInterface |
||
22 | */ |
||
23 | private $phpCsToolProcessor; |
||
24 | |||
25 | /** |
||
26 | * PhpCsTool constructor. |
||
27 | * |
||
28 | * @param OutputInterface $output |
||
29 | * @param PhpCsToolProcessorInterface $phpCsToolProcessor |
||
30 | */ |
||
31 | 2 | public function __construct(OutputInterface $output, PhpCsToolProcessorInterface $phpCsToolProcessor) |
|
36 | |||
37 | /** |
||
38 | * @param array $files |
||
39 | * @param string $standard |
||
40 | * @param string $errorMessage |
||
41 | * @param string $ignore |
||
42 | * |
||
43 | * @throws PhpCsViolationException |
||
44 | */ |
||
45 | 2 | private function execute(array $files, $standard, $errorMessage, $ignore) |
|
65 | |||
66 | /** |
||
67 | * @param CommandInterface|PhpCsTool $command |
||
68 | */ |
||
69 | 2 | public function handle(CommandInterface $command) |
|
78 | } |
||
79 |
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.