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 |
||
8 | class SearchOrdersRequestTest extends TestCase |
||
9 | { |
||
10 | /** |
||
11 | * @test |
||
12 | */ |
||
13 | View Code Duplication | public function it_sets_seller_id_and_returns_itself() |
|
22 | |||
23 | /** |
||
24 | * @test |
||
25 | * @expectedException \LogicException |
||
26 | */ |
||
27 | public function it_cannot_set_seller_id_more_than_once() |
||
34 | |||
35 | /** |
||
36 | * @test |
||
37 | */ |
||
38 | public function it_sets_ordered_datetime_range_and_returns_itself() |
||
51 | |||
52 | /** |
||
53 | * @test |
||
54 | * @expectedException \LogicException |
||
55 | */ |
||
56 | public function it_cannot_set_ordered_datetime_range_when_to_is_earlier_than_from() |
||
65 | |||
66 | /** |
||
67 | * @test |
||
68 | */ |
||
69 | public function it_does_not_set_ordered_datetime_range_when_null() |
||
87 | |||
88 | /** |
||
89 | * @test |
||
90 | * @expectedException \LogicException |
||
91 | */ |
||
92 | View Code Duplication | public function it_cannot_set_from_of_ordered_datetime_range_more_than_once() |
|
99 | |||
100 | /** |
||
101 | * @test |
||
102 | * @expectedException \LogicException |
||
103 | */ |
||
104 | View Code Duplication | public function it_cannot_set_to_of_ordered_datetime_range_more_than_once() |
|
111 | |||
112 | /** |
||
113 | * @test |
||
114 | * @expectedException \InvalidArgumentException |
||
115 | */ |
||
116 | public function it_cannot_set_ordered_datetime_range_to_both_null() |
||
122 | |||
123 | /** |
||
124 | * @test |
||
125 | */ |
||
126 | View Code Duplication | public function it_sets_offset() |
|
137 | |||
138 | /** |
||
139 | * @test |
||
140 | * @expectedException \LogicException |
||
141 | */ |
||
142 | View Code Duplication | public function it_cannot_set_offset_more_than_once() |
|
150 | |||
151 | /** |
||
152 | * @test |
||
153 | * @expectedException \InvalidArgumentException |
||
154 | */ |
||
155 | public function it_cannot_set_offset_to_less_than_zero() |
||
161 | |||
162 | |||
163 | |||
164 | |||
165 | /** |
||
166 | * @test |
||
167 | */ |
||
168 | View Code Duplication | public function it_sets_limit() |
|
179 | |||
180 | /** |
||
181 | * @test |
||
182 | * @expectedException \LogicException |
||
183 | */ |
||
184 | View Code Duplication | public function it_cannot_set_limit_more_than_once() |
|
192 | |||
193 | /** |
||
194 | * @test |
||
195 | * @expectedException \InvalidArgumentException |
||
196 | */ |
||
197 | public function it_cannot_set_limit_to_less_than_zero() |
||
203 | |||
204 | /** |
||
205 | * @test |
||
206 | * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
||
207 | */ |
||
208 | public function it_validates_that_seller_id_is_set() |
||
214 | } |
||
215 |
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.