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 UrlTest4GetBaseUrl extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | //------------------------------------------------------// |
||
24 | // テストメソッド定義 |
||
25 | //------------------------------------------------------// |
||
26 | /** |
||
27 | * setUp() |
||
28 | * |
||
29 | * テストに必要な準備を実施 |
||
30 | */ |
||
31 | protected function setUp() |
||
34 | |||
35 | /** |
||
36 | * test_GetBaseUrl_WithoutArg() |
||
37 | * |
||
38 | * getBaseUrl()の動作をテストする(引数なし) |
||
39 | */ |
||
40 | public function test_GetBaseUrl_WithoutArg() |
||
46 | |||
47 | /** |
||
48 | * test_GetBaseUrl_WithNormalPart1() |
||
49 | * |
||
50 | * getBaseUrl()の動作をテストする(ノーマルな指定その1) |
||
51 | */ |
||
52 | View Code Duplication | public function test_GetBaseUrl_WithNormalPart1() |
|
63 | |||
64 | /** |
||
65 | * test_GetBaseUrl_WithNormalPart2() |
||
66 | * |
||
67 | * getBaseUrl()の動作をテストする(ノーマルな指定その2) |
||
68 | */ |
||
69 | View Code Duplication | public function test_GetBaseUrl_WithNormalPart2() |
|
80 | |||
81 | /** |
||
82 | * test_GetBaseUrl_WithNormalPart3() |
||
83 | * |
||
84 | * getBaseUrl()の動作をテストする(ノーマルな指定その3) |
||
85 | */ |
||
86 | View Code Duplication | public function test_GetBaseUrl_WithNormalPart3() |
|
97 | |||
98 | /** |
||
99 | * test_GetBaseUrl_WithSslPart1() |
||
100 | * |
||
101 | * getBaseUrl()の動作をテストする(SSLな指定その1) |
||
102 | */ |
||
103 | View Code Duplication | public function test_GetBaseUrl_WithSslPart1() |
|
114 | |||
115 | /** |
||
116 | * test_GetBaseUrl_WithSslPart2() |
||
117 | * |
||
118 | * getBaseUrl()の動作をテストする(SSLな指定その2) |
||
119 | */ |
||
120 | View Code Duplication | public function test_GetBaseUrl_WithSslPart2() |
|
131 | |||
132 | /** |
||
133 | * test_GetBaseUrl_WithNotStdPortPart1() |
||
134 | * |
||
135 | * getBaseUrl()の動作をテストする(8000ポートを指定) |
||
136 | */ |
||
137 | View Code Duplication | public function test_GetBaseUrl_WithNotStdPortPart1() |
|
148 | |||
149 | /** |
||
150 | * test_GetBaseUrl_WithNotStdPortPart2() |
||
151 | * |
||
152 | * getBaseUrl()の動作をテストする(8443ポートを指定) |
||
153 | */ |
||
154 | View Code Duplication | public function test_GetBaseUrl_WithNotStdPortPart2() |
|
165 | |||
166 | /** |
||
167 | * test_GetBaseUrl_WithNotStdPortPart3() |
||
168 | * |
||
169 | * getBaseUrl()の動作をテストする(8888ポートを指定) |
||
170 | */ |
||
171 | View Code Duplication | public function test_GetBaseUrl_WithNotStdPortPart3() |
|
182 | } |
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.