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 UserGroupTest extends PHPUnit_Framework_TestCase |
||
| 20 | { |
||
| 21 | use ValueObjectTestTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @covers \eZ\Publish\Core\Repository\Values\User\UserGroup::__construct |
||
| 25 | */ |
||
| 26 | public function testNewClass() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Test a new class and default values on properties. |
||
| 43 | * |
||
| 44 | * @covers \eZ\Publish\API\Repository\Values\User\User::__construct |
||
| 45 | */ |
||
| 46 | View Code Duplication | public function testGetName() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Test retrieving missing property. |
||
| 62 | * |
||
| 63 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__get |
||
| 64 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
||
| 65 | */ |
||
| 66 | public function testMissingProperty() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Test setting read only property. |
||
| 75 | * |
||
| 76 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__set |
||
| 77 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
| 78 | */ |
||
| 79 | public function testReadOnlyProperty() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Test if property exists. |
||
| 88 | * |
||
| 89 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__isset |
||
| 90 | */ |
||
| 91 | public function testIsPropertySet() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Test unsetting a property. |
||
| 103 | * |
||
| 104 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__unset |
||
| 105 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
| 106 | */ |
||
| 107 | public function testUnsetProperty() |
||
| 113 | } |
||
| 114 |
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.