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 |
||
14 | class DelayMaintenanceSQL implements SQLInterface |
||
15 | { |
||
16 | use SQLTrait; |
||
17 | |||
18 | /** |
||
19 | * @var PDO |
||
20 | */ |
||
21 | private $pdo; |
||
22 | |||
23 | /** |
||
24 | * Maintenance constructor. |
||
25 | * |
||
26 | * @param PDO $pdo |
||
27 | */ |
||
28 | public function __construct(PDO $pdo) |
||
32 | |||
33 | /** |
||
34 | * Clean the delay table |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | public function clean() |
||
47 | |||
48 | /** |
||
49 | * Create SQL table |
||
50 | * |
||
51 | * @return bool |
||
52 | * @throws SQLException |
||
53 | */ |
||
54 | View Code Duplication | public function setup() |
|
61 | } |
||
62 |
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.