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 |
||
12 | class Maintenance implements RobotsTxtInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var PDO |
||
16 | */ |
||
17 | protected $pdo; |
||
18 | |||
19 | /** |
||
20 | * Maintenance constructor. |
||
21 | * |
||
22 | * @param PDO $pdo |
||
23 | */ |
||
24 | public function __construct(PDO $pdo) |
||
28 | |||
29 | /** |
||
30 | * Clean all tables automatically |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function autoClean() |
||
40 | |||
41 | /** |
||
42 | * Clean the cache table |
||
43 | * |
||
44 | * @param int $delay - in seconds |
||
45 | * @return bool |
||
46 | */ |
||
47 | View Code Duplication | public function cleanCache($delay = self::CACHE_TIME) |
|
57 | |||
58 | /** |
||
59 | * Clean the delay table |
||
60 | * |
||
61 | * @param int $delay - in seconds |
||
62 | * @return bool |
||
63 | */ |
||
64 | View Code Duplication | public function cleanDelay($delay = 60) |
|
74 | } |
||
75 |
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.