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 |
||
21 | class ValidateTest4IsBetween extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | //------------------------------------------------------// |
||
24 | // テストメソッド定義 |
||
25 | //------------------------------------------------------// |
||
26 | /** |
||
27 | * setUp() |
||
28 | * |
||
29 | * テストに必要な準備を実施 |
||
30 | */ |
||
31 | protected function setUp() |
||
34 | |||
35 | /** |
||
36 | * test_IsBetween_InRangePart1() |
||
37 | * |
||
38 | * IsLeapYear()の挙動をテストする(範囲内:全て同値) |
||
39 | */ |
||
40 | View Code Duplication | public function test_IsBetween_InRangePart1() |
|
48 | |||
49 | /** |
||
50 | * test_IsBetween_InRangePart2() |
||
51 | * |
||
52 | * IsLeapYear()の挙動をテストする(範囲内:下限値と同値) |
||
53 | */ |
||
54 | View Code Duplication | public function test_IsBetween_InRangePart2() |
|
62 | |||
63 | /** |
||
64 | * test_IsBetween_InRangePart3() |
||
65 | * |
||
66 | * IsLeapYear()の挙動をテストする(範囲内:上限値と同値) |
||
67 | */ |
||
68 | View Code Duplication | public function test_IsBetween_InRangePart3() |
|
76 | |||
77 | /** |
||
78 | * test_IsBetween_InRangePart4() |
||
79 | * |
||
80 | * IsLeapYear()の挙動をテストする(範囲内:下限値と同値、負数) |
||
81 | */ |
||
82 | public function test_IsBetween_InRangePart4() |
||
90 | |||
91 | /** |
||
92 | * test_IsBetween_InRangePart5() |
||
93 | * |
||
94 | * IsLeapYear()の挙動をテストする(範囲内:上限値と同値、負数) |
||
95 | */ |
||
96 | public function test_IsBetween_InRangePart5() |
||
104 | |||
105 | /** |
||
106 | * test_IsBetween_InRangePart6() |
||
107 | * |
||
108 | * IsLeapYear()の挙動をテストする(範囲内:下限値と同値、小数) |
||
109 | */ |
||
110 | View Code Duplication | public function test_IsBetween_InRangePart6() |
|
118 | |||
119 | /** |
||
120 | * test_IsBetween_InRangePart7() |
||
121 | * |
||
122 | * IsLeapYear()の挙動をテストする(範囲内:上限値と同値、小数) |
||
123 | */ |
||
124 | View Code Duplication | public function test_IsBetween_InRangePart7() |
|
132 | |||
133 | /** |
||
134 | * test_IsBetween_InRangePart8() |
||
135 | * |
||
136 | * IsLeapYear()の挙動をテストする(範囲内:下限値と同値、小数) |
||
137 | */ |
||
138 | View Code Duplication | public function test_IsBetween_InRangePart8() |
|
146 | |||
147 | /** |
||
148 | * test_IsBetween_InRangePart9() |
||
149 | * |
||
150 | * IsLeapYear()の挙動をテストする(範囲内:上限値と同値、小数) |
||
151 | */ |
||
152 | View Code Duplication | public function test_IsBetween_InRangePart9() |
|
160 | |||
161 | /** |
||
162 | * test_IsBetween_OutRangePart1() |
||
163 | * |
||
164 | * IsLeapYear()の挙動をテストする(範囲外:下限値より下) |
||
165 | */ |
||
166 | View Code Duplication | public function test_IsBetween_OutRangePart1() |
|
174 | |||
175 | /** |
||
176 | * test_IsBetween_OutRangePart2() |
||
177 | * |
||
178 | * IsLeapYear()の挙動をテストする(範囲外:上限値より上) |
||
179 | */ |
||
180 | View Code Duplication | public function test_IsBetween_OutRangePart2() |
|
188 | |||
189 | /** |
||
190 | * test_IsBetween_OutRangePart3() |
||
191 | * |
||
192 | * IsLeapYear()の挙動をテストする(範囲外:下限値より下、負数) |
||
193 | */ |
||
194 | View Code Duplication | public function test_IsBetween_OutRangePart3() |
|
202 | |||
203 | /** |
||
204 | * test_IsBetween_OutRangePart4() |
||
205 | * |
||
206 | * IsLeapYear()の挙動をテストする(範囲外:上限値より上、負数) |
||
207 | */ |
||
208 | View Code Duplication | public function test_IsBetween_OutRangePart4() |
|
216 | |||
217 | /** |
||
218 | * test_IsBetween_OutRangePart5() |
||
219 | * |
||
220 | * IsLeapYear()の挙動をテストする(範囲外:下限値より下、小数) |
||
221 | */ |
||
222 | View Code Duplication | public function test_IsBetween_OutRangePart5() |
|
230 | |||
231 | /** |
||
232 | * test_IsBetween_OutRangePart6() |
||
233 | * |
||
234 | * IsLeapYear()の挙動をテストする(範囲外:上限値より上、小数) |
||
235 | */ |
||
236 | View Code Duplication | public function test_IsBetween_OutRangePart6() |
|
244 | |||
245 | /** |
||
246 | * test_IsBetween_OutRangePart7() |
||
247 | * |
||
248 | * IsLeapYear()の挙動をテストする(範囲外:下限値より下、負数、小数) |
||
249 | */ |
||
250 | View Code Duplication | public function test_IsBetween_OutRangePart7() |
|
258 | |||
259 | /** |
||
260 | * test_IsBetween_OutRangePart8() |
||
261 | * |
||
262 | * IsLeapYear()の挙動をテストする(範囲外:上限値より上、負数、小数) |
||
263 | */ |
||
264 | View Code Duplication | public function test_IsBetween_OutRangePart8() |
|
272 | } |
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.