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 |
||
28 | abstract class AbstractWindowSettings implements ThrottleSettingsInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var int|null |
||
32 | */ |
||
33 | private $hitLimit; |
||
34 | |||
35 | /** |
||
36 | * @var int|null |
||
37 | */ |
||
38 | private $timeLimit; |
||
39 | |||
40 | /** |
||
41 | * @var int|null |
||
42 | */ |
||
43 | private $cacheTtl; |
||
44 | |||
45 | /** |
||
46 | * @param int|null $tokenLimit |
||
47 | * @param int|null $timeLimit In seconds |
||
48 | * @param int|null $cacheTtl In seconds |
||
49 | */ |
||
50 | 36 | public function __construct($tokenLimit = null, $timeLimit = null, $cacheTtl = null) |
|
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | 6 | public function merge(ThrottleSettingsInterface $settings) |
|
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | 30 | public function isValid() |
|
85 | |||
86 | /** |
||
87 | * @return int|null |
||
88 | */ |
||
89 | 24 | public function getHitLimit() |
|
93 | |||
94 | /** |
||
95 | * @return int|null |
||
96 | */ |
||
97 | 24 | public function getTimeLimit() |
|
101 | |||
102 | /** |
||
103 | * @return int|null |
||
104 | */ |
||
105 | 24 | public function getCacheTtl() |
|
109 | } |
||
110 |
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.