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 |
||
9 | View Code Duplication | final class PreFetchObjectsEventTest extends \PHPUnit_Framework_TestCase |
|
|
|||
10 | { |
||
11 | public function testShouldBeSubClassOfEventClass() |
||
17 | |||
18 | public function testShouldFinal() |
||
24 | |||
25 | public function testCouldBeConstructedWithPagerAndObjectPersisterAndOptions() |
||
29 | |||
30 | public function testShouldAllowGetPagerSetInConstructor() |
||
38 | |||
39 | public function testShouldAllowGetPreviouslySetPager() |
||
48 | |||
49 | public function testShouldAllowGetObjectPersisterSetInConstructor() |
||
57 | |||
58 | public function testShouldAllowGetPreviouslySetObjectsPersister() |
||
67 | |||
68 | public function testShouldAllowGetOptionsSetInConstructor() |
||
76 | |||
77 | public function testShouldAllowGetPreviouslySetOptions() |
||
86 | |||
87 | /** |
||
88 | * @return ObjectPersisterInterface|\PHPUnit_Framework_MockObject_MockObject |
||
89 | */ |
||
90 | private function createObjectPersisterMock() |
||
94 | |||
95 | /** |
||
96 | * @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject |
||
97 | */ |
||
98 | private function createPagerMock() |
||
102 | } |
||
103 |
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.