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 |
||
15 | class Manager implements ManagerInterface |
||
16 | { |
||
17 | use UriParser; |
||
18 | |||
19 | /** |
||
20 | * Database handler |
||
21 | * @var PDO |
||
22 | */ |
||
23 | private $pdo; |
||
24 | |||
25 | /** |
||
26 | * Manager constructor. |
||
27 | * |
||
28 | * @param PDO $pdo |
||
29 | * @throws SQLException |
||
30 | */ |
||
31 | public function __construct(PDO $pdo) |
||
35 | |||
36 | /** |
||
37 | * Clean the delay table |
||
38 | * |
||
39 | * @param int $delay - in seconds |
||
40 | * @return bool |
||
41 | */ |
||
42 | View Code Duplication | public function clean($delay = 60) |
|
52 | |||
53 | /** |
||
54 | * Top X wait time |
||
55 | * |
||
56 | * @param int $limit |
||
57 | * @param int $min |
||
58 | * @return array |
||
59 | */ |
||
60 | public function getTopWaitTimes($limit = 100, $min = 0) |
||
82 | } |
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.