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 |
||
21 | abstract class MappedStatementRepositoryTest extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
25 | */ |
||
26 | private $objectManager; |
||
27 | |||
28 | /** |
||
29 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
30 | */ |
||
31 | private $unitOfWork; |
||
32 | |||
33 | /** |
||
34 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
35 | */ |
||
36 | private $classMetadata; |
||
37 | |||
38 | /** |
||
39 | * @var MappedStatementRepository |
||
40 | */ |
||
41 | private $repository; |
||
42 | |||
43 | protected function setUp() |
||
50 | |||
51 | View Code Duplication | public function testStatementDocumentIsPersisted() |
|
63 | |||
64 | View Code Duplication | public function testFlushIsCalledByDefault() |
|
75 | |||
76 | View Code Duplication | public function testCallToFlushCanBeSuppressed() |
|
87 | |||
88 | abstract protected function getObjectManagerClass(); |
||
89 | |||
90 | protected function createObjectManagerMock() |
||
97 | |||
98 | abstract protected function getUnitOfWorkClass(); |
||
99 | |||
100 | protected function createUnitOfWorkMock() |
||
107 | |||
108 | abstract protected function getClassMetadataClass(); |
||
109 | |||
110 | protected function createClassMetadataMock() |
||
117 | |||
118 | abstract protected function createMappedStatementRepository($objectManager, $unitOfWork, $classMetadata); |
||
119 | } |
||
120 |
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.