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 EntitySimpleGetterSetterTest extends AbstractApplyTest |
||
14 | { |
||
15 | const CLASS_NAME = 'TestEntity'; |
||
16 | |||
17 | /** |
||
18 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
19 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
20 | */ |
||
21 | public function testApplyNoEntity() |
||
35 | |||
36 | /** |
||
37 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
38 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
39 | */ |
||
40 | View Code Duplication | public function testValidEntity() |
|
51 | |||
52 | /** |
||
53 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
54 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
55 | */ |
||
56 | View Code Duplication | public function testValidEntityWithWhitelist() |
|
63 | |||
64 | /** |
||
65 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
66 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
67 | */ |
||
68 | View Code Duplication | public function testWrongMethodPrefix() |
|
75 | |||
76 | /** |
||
77 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
78 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
79 | */ |
||
80 | public function testForbiddenScope() |
||
89 | |||
90 | /** |
||
91 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
92 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
93 | */ |
||
94 | View Code Duplication | public function testMultipleReturns() |
|
105 | |||
106 | /** |
||
107 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
108 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
109 | */ |
||
110 | public function testRelationReturnToThis() |
||
130 | |||
131 | /** |
||
132 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
133 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
134 | */ |
||
135 | View Code Duplication | public function testAbstractClass() |
|
143 | |||
144 | /** |
||
145 | * @covers MS\PHPMD\Rule\Symfony2\EntitySimpleGetterSetter |
||
146 | * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
||
147 | */ |
||
148 | public function testForceClassIsAnEntity() |
||
164 | |||
165 | /** |
||
166 | * @param array $methodNodes |
||
167 | * |
||
168 | * @return \Mockery\MockInterface |
||
169 | */ |
||
170 | private function getClassNode(array $methodNodes) |
||
180 | |||
181 | /** |
||
182 | * @return EntitySimpleGetterSetter |
||
183 | */ |
||
184 | protected function getRule() |
||
195 | } |
||
196 |
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.