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 | class UserGroupTest extends PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | use ValueObjectTestTrait; |
||
24 | |||
25 | /** |
||
26 | * @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::__construct |
||
27 | */ |
||
28 | public function testNewClass() |
||
42 | |||
43 | /** |
||
44 | * Test getName method. |
||
45 | * |
||
46 | * @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::getName |
||
47 | */ |
||
48 | View Code Duplication | public function testGetName() |
|
61 | |||
62 | /** |
||
63 | * Test retrieving missing property. |
||
64 | * |
||
65 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__get |
||
66 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
||
67 | */ |
||
68 | public function testMissingProperty() |
||
74 | |||
75 | /** |
||
76 | * @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::getProperties |
||
77 | */ |
||
78 | View Code Duplication | public function testObjectProperties() |
|
99 | |||
100 | /** |
||
101 | * Test setting read only property. |
||
102 | * |
||
103 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__set |
||
104 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
105 | */ |
||
106 | public function testReadOnlyProperty() |
||
112 | |||
113 | /** |
||
114 | * Test if property exists. |
||
115 | * |
||
116 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__isset |
||
117 | */ |
||
118 | public function testIsPropertySet() |
||
127 | |||
128 | /** |
||
129 | * Test unsetting a property. |
||
130 | * |
||
131 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__unset |
||
132 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
133 | */ |
||
134 | public function testUnsetProperty() |
||
140 | } |
||
141 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.