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 |
||
26 | class AsynchronousClient implements ClientInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var LoopInterface |
||
30 | */ |
||
31 | private $loop; |
||
32 | |||
33 | /** |
||
34 | * @var ClientFactory |
||
35 | */ |
||
36 | private $clientFactory; |
||
37 | |||
38 | /** |
||
39 | * @var ObjectArrayFactory |
||
40 | */ |
||
41 | private $objectArrayFactory; |
||
42 | |||
43 | /** |
||
44 | * AsynchronousClient constructor. |
||
45 | * @param LoopInterface $loop |
||
46 | * @param ClientFactory $clientFactory |
||
47 | * @param ObjectArrayFactory $objectArrayFactory |
||
48 | */ |
||
49 | public function __construct( |
||
58 | |||
59 | /** |
||
60 | * @param ObjectArray $urls |
||
61 | * @return ObjectArray |
||
62 | */ |
||
63 | View Code Duplication | public function getContent(ObjectArray $urls): ObjectArray |
|
73 | |||
74 | /** |
||
75 | * @codeCoverageIgnore |
||
76 | * @param UrlInterface $url |
||
77 | * @param ObjectArray $htmlObjectArray |
||
78 | * @return void |
||
79 | */ |
||
80 | View Code Duplication | private function createRequestDefinition(UrlInterface $url, ObjectArray &$htmlObjectArray): void |
|
100 | } |
||
101 |
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.