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 |
||
9 | final class ProcessesExecutor implements ProcessesExecutorInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var LoggerInterface |
||
13 | */ |
||
14 | private $logger; |
||
15 | |||
16 | /** |
||
17 | * @param LoggerInterface|null $logger |
||
18 | */ |
||
19 | 7 | public function __construct(LoggerInterface $logger = null) |
|
23 | |||
24 | /** |
||
25 | * @param Process[]|array $processes |
||
26 | * @param callable|null $startCallback |
||
27 | * @param callable|null $iterationCallback |
||
28 | * @param callable|null $finishCallback |
||
29 | * @param int $parallelProcessCount |
||
30 | * @param int $iterationSleepInMicroseconds |
||
31 | */ |
||
32 | 7 | public function execute( |
|
72 | |||
73 | /** |
||
74 | * @param Process $process |
||
75 | * @param mixed $key |
||
76 | * @param callable|null $startCallback |
||
77 | */ |
||
78 | 6 | View Code Duplication | private function startCallback(Process $process, $key, callable $startCallback = null) |
88 | |||
89 | /** |
||
90 | * @param Process[]|array $processes |
||
91 | * @param callable|null $iterationCallback |
||
92 | */ |
||
93 | 7 | private function callIterationCallback(array $processes, callable $iterationCallback = null) |
|
103 | |||
104 | /** |
||
105 | * @param Process $process |
||
106 | * @param mixed $key |
||
107 | * @param callable|null $finishCallback |
||
108 | */ |
||
109 | 6 | View Code Duplication | private function finishCallback(Process $process, $key, callable $finishCallback = null) |
119 | } |
||
120 |
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.