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 TextTest4AutoUrlLink extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | //------------------------------------------------------// |
||
24 | // テストメソッド定義 |
||
25 | //------------------------------------------------------// |
||
26 | /** |
||
27 | * setUp() |
||
28 | * |
||
29 | * テストに必要な準備を実施 |
||
30 | */ |
||
31 | protected function setUp() |
||
34 | |||
35 | /** |
||
36 | * test_AutoUrlLink_WithNoLinks() |
||
37 | * |
||
38 | * autoUrlLink()の挙動をテストする(URLが含まれないテキストの場合) |
||
39 | */ |
||
40 | public function test_AutoUrlLink_WithNoLinks() |
||
47 | |||
48 | /** |
||
49 | * test_AutoUrlLink_WithOneHttpLink() |
||
50 | * |
||
51 | * autoUrlLink()の挙動をテストする(URL(http://~)が1つだけ含まれるテキストの場合) |
||
52 | */ |
||
53 | public function test_AutoUrlLink_WithOneHttpLink() |
||
60 | |||
61 | /** |
||
62 | * test_AutoUrlLink_WithOneHttpsLink() |
||
63 | * |
||
64 | * autoUrlLink()の挙動をテストする(URL(https://~)が1つだけ含まれるテキストの場合) |
||
65 | */ |
||
66 | public function test_AutoUrlLink_WithOneHttpsLink() |
||
73 | |||
74 | /** |
||
75 | * test_AutoUrlLink_WithTwoHttpLinks() |
||
76 | * |
||
77 | * autoUrlLink()の挙動をテストする(URL(http://~)が2つ含まれるテキストの場合) |
||
78 | */ |
||
79 | public function test_AutoUrlLink_WithTwoHttpLinks() |
||
86 | |||
87 | /** |
||
88 | * test_AutoUrlLink_WithTwoHttpsLinks() |
||
89 | * |
||
90 | * autoUrlLink()の挙動をテストする(URL(https://~)が2つ含まれるテキストの場合) |
||
91 | */ |
||
92 | public function test_AutoUrlLink_WithTwoHttpsLinks() |
||
99 | |||
100 | /** |
||
101 | * test_AutoUrlLink_WithHttpAndHttpLinks() |
||
102 | * |
||
103 | * autoUrlLink()の挙動をテストする(URL(http://~とhttps://~)が2つ含まれるテキストの場合) |
||
104 | */ |
||
105 | public function test_AutoUrlLink_WithHttpAndHttpLinks() |
||
112 | |||
113 | /** |
||
114 | * test_AutoUrlLink_WithNoLinks_WithoutNewWindow() |
||
115 | * |
||
116 | * autoUrlLink()の挙動をテストする(URLが含まれないテキストの場合、新規ウインドウモードOFF) |
||
117 | */ |
||
118 | public function test_AutoUrlLink_WithNoLinks_WithoutNewWindow() |
||
125 | |||
126 | /** |
||
127 | * test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow() |
||
128 | * |
||
129 | * autoUrlLink()の挙動をテストする(URL(http://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF) |
||
130 | */ |
||
131 | public function test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow() |
||
138 | |||
139 | /** |
||
140 | * test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow() |
||
141 | * |
||
142 | * autoUrlLink()の挙動をテストする(URL(https://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF) |
||
143 | */ |
||
144 | public function test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow() |
||
151 | |||
152 | /** |
||
153 | * test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow() |
||
154 | * |
||
155 | * autoUrlLink()の挙動をテストする(URL(http://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF) |
||
156 | */ |
||
157 | public function test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow() |
||
164 | |||
165 | /** |
||
166 | * test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow() |
||
167 | * |
||
168 | * autoUrlLink()の挙動をテストする(URL(https://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF) |
||
169 | */ |
||
170 | public function test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow() |
||
177 | |||
178 | /** |
||
179 | * test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow() |
||
180 | * |
||
181 | * autoUrlLink()の挙動をテストする(URL(http://~とhttps://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF) |
||
182 | */ |
||
183 | public function test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow() |
||
190 | |||
191 | /** |
||
192 | * test_AutoUrlLink_WithNoLinks_WithoutNewWindow_WithExtraAttr() |
||
193 | * |
||
194 | * autoUrlLink()の挙動をテストする(URLが含まれないテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
||
195 | */ |
||
196 | View Code Duplication | public function test_AutoUrlLink_WithNoLinks_WithoutNewWindow_WithExtraAttr() |
|
204 | |||
205 | /** |
||
206 | * test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow_WithExtraAttr() |
||
207 | * |
||
208 | * autoUrlLink()の挙動をテストする(URL(http://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
||
209 | */ |
||
210 | View Code Duplication | public function test_AutoUrlLink_WithOneHttpLink_WithoutNewWindow_WithExtraAttr() |
|
218 | |||
219 | /** |
||
220 | * test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow_WithExtraAttr() |
||
221 | * |
||
222 | * autoUrlLink()の挙動をテストする(URL(https://~)が1つだけ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
||
223 | */ |
||
224 | View Code Duplication | public function test_AutoUrlLink_WithOneHttpsLink_WithoutNewWindow_WithExtraAttr() |
|
232 | |||
233 | /** |
||
234 | * test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow_WithExtraAttr() |
||
235 | * |
||
236 | * autoUrlLink()の挙動をテストする(URL(http://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
||
237 | */ |
||
238 | View Code Duplication | public function test_AutoUrlLink_WithTwoHttpLinks_WithoutNewWindow_WithExtraAttr() |
|
246 | |||
247 | /** |
||
248 | * test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow_WithExtraAttr() |
||
249 | * |
||
250 | * autoUrlLink()の挙動をテストする(URL(https://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
||
251 | */ |
||
252 | View Code Duplication | public function test_AutoUrlLink_WithTwoHttpsLinks_WithoutNewWindow_WithExtraAttr() |
|
260 | |||
261 | /** |
||
262 | * test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow_WithExtraAttr() |
||
263 | * |
||
264 | * autoUrlLink()の挙動をテストする(URL(http://~とhttps://~)が2つ含まれるテキストの場合、新規ウインドウモードOFF、アトリビュート有り) |
||
265 | */ |
||
266 | View Code Duplication | public function test_AutoUrlLink_WithHttpAndHttpsLinks_WithoutNewWindow_WithExtraAttr() |
|
274 | } |
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.