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 |
||
18 | class VarnishUrlRegenerator extends AbstractQueueHandler implements VarnishUrlRegeneratorInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | const PROCESS_TYPE = 'REGENERATE'; |
||
24 | |||
25 | /** |
||
26 | * @param string $url |
||
27 | * @return void |
||
28 | */ |
||
29 | public function addUrlToRegenerate(string $url): void |
||
34 | |||
35 | /** |
||
36 | * @return void |
||
37 | */ |
||
38 | View Code Duplication | public function runRegenerationQueue(): void |
|
49 | |||
50 | /** |
||
51 | * @return int |
||
52 | */ |
||
53 | protected function getMaxNumberOfProcesses(): int |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | protected function getQueueProcessType(): string |
||
65 | |||
66 | /** |
||
67 | * @param string $url |
||
68 | * @return void |
||
69 | */ |
||
70 | View Code Duplication | private function createRequest(string $url): void |
|
86 | } |
||
87 |
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.