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 |
||
25 | class VarnishUrlPurger extends AbstractQueueHandler implements VarnishUrlPurgerInterface |
||
26 | { |
||
27 | const CURL_CUSTOMREQUEST = 'PURGE'; |
||
28 | const PROCESS_TYPE = 'PURGE'; |
||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | private $verifyPeer = true; |
||
34 | |||
35 | /** |
||
36 | * @var PurgingConfigProviderInterface |
||
37 | */ |
||
38 | private $purgingConfigProvider; |
||
39 | |||
40 | /** |
||
41 | * VarnishUrlPurger constructor. |
||
42 | * @param GeneralConfigProviderInterface $configProvider |
||
43 | * @param LoggerInterface $logger |
||
44 | * @param QueueProgressLoggerInterface $queueProgressLogger |
||
45 | * @param PurgingConfigProviderInterface $purgingConfigProvider |
||
46 | */ |
||
47 | public function __construct( |
||
56 | |||
57 | /** |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function isVerifyPeer(): bool |
||
64 | |||
65 | /** |
||
66 | * @param bool $verifyPeer |
||
67 | * @return void |
||
68 | */ |
||
69 | public function setVerifyPeer(bool $verifyPeer): void |
||
73 | |||
74 | /** |
||
75 | * @param string $url |
||
76 | * @return void |
||
77 | */ |
||
78 | public function addUrlToPurge(string $url): void |
||
83 | |||
84 | /** |
||
85 | * @return void |
||
86 | */ |
||
87 | public function runPurgeQueue(): void |
||
92 | |||
93 | /** |
||
94 | * @return void |
||
95 | */ |
||
96 | protected function buildQueue(): void |
||
118 | |||
119 | /** |
||
120 | * @return void |
||
121 | */ |
||
122 | View Code Duplication | protected function runQueueProcesses(): void |
|
132 | |||
133 | /** |
||
134 | * @return int |
||
135 | */ |
||
136 | protected function getMaxNumberOfProcesses(): int |
||
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | protected function getQueueProcessType(): string |
||
148 | |||
149 | /** |
||
150 | * @return array |
||
151 | */ |
||
152 | private function buildHeaders(): array |
||
162 | } |
||
163 |
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.