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 DateTest4GenYear extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | //------------------------------------------------------// |
||
24 | // テストメソッド定義 |
||
25 | //------------------------------------------------------// |
||
26 | /** |
||
27 | * setUp() |
||
28 | * |
||
29 | * テストに必要な準備を実施 |
||
30 | */ |
||
31 | protected function setUp() |
||
34 | |||
35 | /** |
||
36 | * test_GenYear_NoArgs() |
||
37 | * |
||
38 | * GenYear()の挙動をテストする(引数なし) |
||
39 | */ |
||
40 | public function test_GenYear_NoArgs() |
||
58 | |||
59 | /** |
||
60 | * test_GenYear_Args1() |
||
61 | * |
||
62 | * GenYear()の挙動をテストする(引数1つ) |
||
63 | */ |
||
64 | View Code Duplication | public function test_GenYear_Args1() |
|
83 | |||
84 | /** |
||
85 | * test_GenYear_Args2() |
||
86 | * |
||
87 | * GenYear()の挙動をテストする(引数2つ) |
||
88 | */ |
||
89 | View Code Duplication | public function test_GenYear_Args2() |
|
108 | |||
109 | |||
110 | /** |
||
111 | * test_GenYear_Args4() |
||
112 | * |
||
113 | * GenYear()の挙動をテストする(引数4つ) |
||
114 | */ |
||
115 | public function test_GenYear_Args4() |
||
133 | |||
134 | /** |
||
135 | * test_GenYear_Args5() |
||
136 | * |
||
137 | * GenYear()の挙動をテストする(引数5つ) |
||
138 | */ |
||
139 | public function test_GenYear_Args5() |
||
149 | } |
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.