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 |
||
13 | class RequestTest extends \PHPUnit_Framework_TestCase |
||
14 | { |
||
15 | /** |
||
16 | * @var Request |
||
17 | */ |
||
18 | private $request; |
||
19 | |||
20 | /** |
||
21 | * @var PreApproval |
||
22 | */ |
||
23 | private $preApproval; |
||
24 | |||
25 | protected function setUp() |
||
30 | |||
31 | /** |
||
32 | * @test |
||
33 | */ |
||
34 | public function constructShouldConfigureTheAttributes() |
||
38 | |||
39 | /** |
||
40 | * @test |
||
41 | */ |
||
42 | public function getPreApprovalShouldReturnConfiguredPreApproval() |
||
46 | |||
47 | /** |
||
48 | * @test |
||
49 | */ |
||
50 | public function getReferenceShouldReturnConfiguredReference() |
||
56 | |||
57 | /** |
||
58 | * @test |
||
59 | */ |
||
60 | public function setReferenceShouldChangeTheAttribute() |
||
66 | |||
67 | /** |
||
68 | * @test |
||
69 | */ |
||
70 | public function getRedirectToShouldReturnConfiguredRedirectTo() |
||
76 | |||
77 | /** |
||
78 | * @test |
||
79 | */ |
||
80 | public function setRedirectToShouldChangeTheAttribute() |
||
86 | |||
87 | /** |
||
88 | * @test |
||
89 | */ |
||
90 | public function getReviewOnShouldReturnConfiguredReviewOn() |
||
96 | |||
97 | /** |
||
98 | * @test |
||
99 | */ |
||
100 | public function setReviewOnToShouldChangeTheAttribute() |
||
106 | |||
107 | /** |
||
108 | * @test |
||
109 | */ |
||
110 | View Code Duplication | public function getCustomerShouldReturnConfiguredCustomer() |
|
117 | |||
118 | /** |
||
119 | * @test |
||
120 | */ |
||
121 | View Code Duplication | public function setCustomerToShouldChangeTheAttribute() |
|
128 | |||
129 | public function testSerializeShouldXMLFull() |
||
160 | } |
||
161 |
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.