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 |
||
11 | class TestScalarDataProvider |
||
12 | { |
||
13 | |||
14 | |||
15 | public static function getsList() |
||
25 | |||
26 | public static function getIntTestData() |
||
49 | |||
50 | public static function getFloatTestData() |
||
65 | |||
66 | public static function getStringTestData() |
||
78 | |||
79 | public static function getBooleanTestData() |
||
94 | |||
95 | public static function getIdTestData() |
||
103 | |||
104 | View Code Duplication | public static function getDatetimeTestData() |
|
|
|||
105 | { |
||
106 | $time = time(); |
||
107 | return [ |
||
108 | [null, null, true], |
||
109 | [(new \DateTime())->setTimestamp($time), date('Y-m-d H:i:s', $time), true], |
||
110 | ]; |
||
111 | } |
||
112 | |||
113 | View Code Duplication | public static function getDatetimetzTestData() |
|
114 | { |
||
115 | $time = time(); |
||
116 | return [ |
||
117 | [null, null, true], |
||
118 | [(new \DateTime())->setTimestamp($time), date('r', $time), true], |
||
119 | ]; |
||
120 | } |
||
121 | |||
122 | View Code Duplication | public static function getDateTestData() |
|
123 | { |
||
124 | $time = time(); |
||
125 | return [ |
||
126 | [null, null, true], |
||
127 | [(new \DateTime())->setTimestamp($time), date('Y-m-d', $time), true], |
||
128 | ]; |
||
129 | } |
||
130 | |||
131 | |||
132 | public static function getTimestampTestData() |
||
140 | |||
141 | } |
||
142 |
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.