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 |
||
19 | class BnDateTimeTest extends TestCase |
||
20 | { |
||
21 | public function flagDataProvider() |
||
25 | |||
26 | public function enFlagDataProvider() |
||
30 | |||
31 | public function dataProviderForFlag_t() |
||
35 | |||
36 | public function dataProviderEnSuffix() { |
||
46 | |||
47 | /** |
||
48 | * @dataProvider flagDataProvider |
||
49 | * @param $time |
||
50 | * @param $flag |
||
51 | * @param $expected |
||
52 | */ |
||
53 | public function testFormat($time, $flag, $expected) |
||
58 | |||
59 | public function testFactoryShouldReturnNullForNullValue() |
||
64 | |||
65 | public function testFactoryShouldCreateBnDateTimeObjectFromString() |
||
71 | |||
72 | public function testFactoryShouldReturnSameObjectIfBnDateObjectGiven() |
||
77 | |||
78 | View Code Duplication | public function testFactoryShouldReturnBnDateTimeObjectWithSameNativeDateTime() |
|
85 | |||
86 | View Code Duplication | public function testFactoryShouldReturnBnDateTimeObjectFromTimeStamp() |
|
93 | |||
94 | /** |
||
95 | * @expectedException \Exception |
||
96 | */ |
||
97 | public function testFactoryForInvalidInputShouldThrowException() |
||
103 | |||
104 | /** |
||
105 | * @dataProvider enFlagDataProvider |
||
106 | * @param $time |
||
107 | * @param $flag |
||
108 | * @param $expected |
||
109 | */ |
||
110 | public function testEnFormat($time, $flag, $expected) |
||
115 | |||
116 | /** |
||
117 | * @dataProvider dataProviderEnSuffix |
||
118 | * @param $day |
||
119 | * @param $suffix |
||
120 | */ |
||
121 | public function testEnSuffix($day, $suffix) { |
||
125 | |||
126 | /** |
||
127 | * @dataProvider dataProviderForFlag_t |
||
128 | * @param $time |
||
129 | * @param $expected |
||
130 | */ |
||
131 | public function testDayInMonth($time, $expected) |
||
136 | |||
137 | public function testCustomMorningTest() |
||
144 | |||
145 | public function testBanglaDateSetting() |
||
150 | |||
151 | public function testDateTimeObject() |
||
156 | |||
157 | protected function createObjectAndSetBanglaDate($time, $year, $month, $day) |
||
161 | |||
162 | /** |
||
163 | * @param $time |
||
164 | * @return BnDateTime |
||
165 | */ |
||
166 | protected function createObject($time) |
||
170 | } |
||
171 |
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.