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 |
||
18 | View Code Duplication | class ObjectStateGroupTest extends PHPUnit_Framework_TestCase |
|
|
|||
19 | { |
||
20 | use ValueObjectTestTrait; |
||
21 | |||
22 | /** |
||
23 | * Test a new class and default values on properties. |
||
24 | * |
||
25 | * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__construct |
||
26 | */ |
||
27 | public function testNewClass() |
||
43 | |||
44 | /** |
||
45 | * Test retrieving missing property. |
||
46 | * |
||
47 | * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__get |
||
48 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
||
49 | */ |
||
50 | public function testMissingProperty() |
||
56 | |||
57 | /** |
||
58 | * Test setting read only property. |
||
59 | * |
||
60 | * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__set |
||
61 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
62 | */ |
||
63 | public function testReadOnlyProperty() |
||
69 | |||
70 | /** |
||
71 | * Test if property exists. |
||
72 | * |
||
73 | * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__isset |
||
74 | */ |
||
75 | public function testIsPropertySet() |
||
84 | |||
85 | /** |
||
86 | * Test unsetting a property. |
||
87 | * |
||
88 | * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__unset |
||
89 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
90 | */ |
||
91 | public function testUnsetProperty() |
||
97 | } |
||
98 |
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.