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 UserTest 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\User\User::__construct |
||
26 | */ |
||
27 | public function testNewClass() |
||
43 | |||
44 | /** |
||
45 | * Test retrieving missing property. |
||
46 | * |
||
47 | * @covers \eZ\Publish\API\Repository\Values\User\User::__get |
||
48 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
||
49 | */ |
||
50 | public function testMissingProperty() |
||
56 | |||
57 | /** |
||
58 | * @covers \eZ\Publish\Core\Repository\Values\User\User::getProperties |
||
59 | */ |
||
60 | View Code Duplication | public function testObjectProperties() |
|
81 | |||
82 | /** |
||
83 | * Test setting read only property. |
||
84 | * |
||
85 | * @covers \eZ\Publish\API\Repository\Values\User\User::__set |
||
86 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
87 | */ |
||
88 | public function testReadOnlyProperty() |
||
94 | |||
95 | /** |
||
96 | * Test if property exists. |
||
97 | * |
||
98 | * @covers \eZ\Publish\API\Repository\Values\User\User::__isset |
||
99 | */ |
||
100 | public function testIsPropertySet() |
||
109 | |||
110 | /** |
||
111 | * Test unsetting a property. |
||
112 | * |
||
113 | * @covers \eZ\Publish\API\Repository\Values\User\User::__unset |
||
114 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
115 | */ |
||
116 | public function testUnsetProperty() |
||
122 | } |
||
123 |
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.