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 | * Test setting read only property. |
||
| 77 | * |
||
| 78 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__set |
||
| 79 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
| 80 | */ |
||
| 81 | public function testReadOnlyProperty() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Test if property exists. |
||
| 90 | * |
||
| 91 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__isset |
||
| 92 | */ |
||
| 93 | public function testIsPropertySet() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Test unsetting a property. |
||
| 105 | * |
||
| 106 | * @covers \eZ\Publish\API\Repository\Values\User\UserGroup::__unset |
||
| 107 | * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
||
| 108 | */ |
||
| 109 | public function testUnsetProperty() |
||
| 115 | } |
||
| 116 |
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.