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 |
||
23 | class HalfAsynchronousProcessRunner implements ProcessRunnerInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var LoopInterface |
||
27 | */ |
||
28 | private $loop; |
||
29 | |||
30 | /** |
||
31 | * @var ProcessFactory |
||
32 | */ |
||
33 | private $processFactory; |
||
34 | |||
35 | /** |
||
36 | * AsynchronousProcessRunner constructor. |
||
37 | * @param LoopInterface $loop |
||
38 | * @param ProcessFactory $processFactory |
||
39 | */ |
||
40 | public function __construct( |
||
47 | |||
48 | /** |
||
49 | * @param ObjectArray $processes |
||
50 | * @return void |
||
51 | */ |
||
52 | public function runProcesses(ObjectArray $processes): void |
||
64 | |||
65 | /** |
||
66 | * @codeCoverageIgnore |
||
67 | * @param ProcessInterface $process |
||
68 | * @return void |
||
69 | */ |
||
70 | View Code Duplication | protected function createProcessDefinition(ProcessInterface $process): void |
|
79 | } |
||
80 |
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.