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 |
||
10 | class GetOrderInfoRequestTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @test |
||
14 | */ |
||
15 | View Code Duplication | public function it_sets_seller_id_and_returns_itself() |
|
26 | |||
27 | /** |
||
28 | * @test |
||
29 | * @expectedException \LogicException |
||
30 | */ |
||
31 | public function it_cannot_set_seller_id_more_than_once() |
||
38 | |||
39 | /** |
||
40 | * @test |
||
41 | */ |
||
42 | View Code Duplication | public function it_sets_order_id_and_returns_itself() |
|
53 | |||
54 | /** |
||
55 | * @test |
||
56 | * @expectedException \LogicException |
||
57 | */ |
||
58 | public function it_cannot_set_order_id_more_than_once() |
||
65 | |||
66 | /** |
||
67 | * @test |
||
68 | * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
||
69 | * @expectedExceptionMessage SellerId is required. |
||
70 | */ |
||
71 | public function seller_id_is_not_set() |
||
78 | |||
79 | /** |
||
80 | * @test |
||
81 | * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
||
82 | * @expectedExceptionMessage OrderId is required. |
||
83 | */ |
||
84 | public function order_id_is_not_set() |
||
91 | } |
||
92 |
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.