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 |
||
20 | class Manage extends ManageCore |
||
21 | { |
||
22 | /** |
||
23 | * Process the update queue |
||
24 | * |
||
25 | * @param float|int $timeLimit |
||
26 | * @param int|null $workerID |
||
27 | * @return string[] |
||
28 | * @throws Exceptions\DatabaseException |
||
29 | */ |
||
30 | public function cron($timeLimit = self::CRON_EXEC_TIME, $workerID = self::WORKER_ID) |
||
71 | |||
72 | /** |
||
73 | * Set WorkerID |
||
74 | * |
||
75 | * @param int|null $workerID |
||
76 | * @return int |
||
77 | * @throws \InvalidArgumentException |
||
78 | */ |
||
79 | private function setWorkerID($workerID) |
||
90 | |||
91 | /** |
||
92 | * Base class |
||
93 | * |
||
94 | * @param string $baseUri |
||
95 | * @return Base |
||
96 | */ |
||
97 | public function base($baseUri) |
||
101 | |||
102 | /** |
||
103 | * Clean the cache table |
||
104 | * |
||
105 | * @param int $delay |
||
106 | * @return bool |
||
107 | */ |
||
108 | View Code Duplication | public function clean($delay = self::CLEAN_DELAY) |
|
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.