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 |
||
| 19 | class UserTest extends PHPUnit_Framework_TestCase |
||
| 20 | { |
||
| 21 | use ValueObjectTestTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Test a new class and default values on properties. |
||
| 25 | * |
||
| 26 | * @covers \eZ\Publish\Core\Repository\Values\User\User::__construct |
||
| 27 | */ |
||
| 28 | public function testNewClass() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Test a new class and default values on properties. |
||
| 47 | * |
||
| 48 | * @covers \eZ\Publish\API\Repository\Values\User\User::__construct |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function testGetName() |
|
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * Test retrieving missing property. |
||
| 67 | * |
||
| 68 | * @covers \eZ\Publish\API\Repository\Values\User\User::__get |
||
| 69 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
||
| 70 | */ |
||
| 71 | public function testMissingProperty() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Test setting read only property. |
||
| 80 | * |
||
| 81 | * @covers \eZ\Publish\API\Repository\Values\User\User::__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\User::__isset |
||
| 95 | */ |
||
| 96 | public function testIsPropertySet() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Test unsetting a property. |
||
| 108 | * |
||
| 109 | * @covers \eZ\Publish\API\Repository\Values\User\User::__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@propertyannotation 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.