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 | class UserGroupTest extends PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | use ValueObjectTestTrait; |
||
21 | |||
22 | /** |
||
23 | * @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::__construct |
||
24 | */ |
||
25 | public function testNewClass() |
||
39 | |||
40 | /** |
||
41 | * Test retrieving missing property. |
||
42 | * |
||
43 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__get |
||
44 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
||
45 | */ |
||
46 | public function testMissingProperty() |
||
52 | |||
53 | /** |
||
54 | * @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::getProperties |
||
55 | */ |
||
56 | View Code Duplication | public function testObjectProperties() |
|
77 | |||
78 | /** |
||
79 | * Test setting read only property. |
||
80 | * |
||
81 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__set |
||
82 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
83 | */ |
||
84 | public function testReadOnlyProperty() |
||
90 | |||
91 | /** |
||
92 | * Test if property exists. |
||
93 | * |
||
94 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__isset |
||
95 | */ |
||
96 | public function testIsPropertySet() |
||
105 | |||
106 | /** |
||
107 | * Test unsetting a property. |
||
108 | * |
||
109 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__unset |
||
110 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
111 | */ |
||
112 | public function testUnsetProperty() |
||
118 | } |
||
119 |
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.