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 | abstract class LanguageBase extends BaseServiceTest |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Test a new class and default values on properties. |
||
| 25 | * |
||
| 26 | * @covers \eZ\Publish\API\Repository\Values\Content\Language::__construct |
||
| 27 | */ |
||
| 28 | public function testNewClass() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Test retrieving missing property. |
||
| 45 | * |
||
| 46 | * @covers \eZ\Publish\API\Repository\Values\Content\Language::__get |
||
| 47 | */ |
||
| 48 | public function testMissingProperty() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Test setting read only property. |
||
| 60 | * |
||
| 61 | * @covers \eZ\Publish\API\Repository\Values\Content\Language::__set |
||
| 62 | */ |
||
| 63 | public function testReadOnlyProperty() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Test if property exists. |
||
| 75 | * |
||
| 76 | * @covers \eZ\Publish\API\Repository\Values\Content\Language::__isset |
||
| 77 | */ |
||
| 78 | public function testIsPropertySet() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Test unsetting a property. |
||
| 90 | * |
||
| 91 | * @covers \eZ\Publish\API\Repository\Values\Content\Language::__unset |
||
| 92 | */ |
||
| 93 | public function testUnsetProperty() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Test service method for creating language. |
||
| 105 | * |
||
| 106 | * @covers \eZ\Publish\API\Repository\LanguageService::createLanguage |
||
| 107 | */ |
||
| 108 | public function testCreateLanguage() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Test service method for creating language throwing InvalidArgumentException. |
||
| 134 | * |
||
| 135 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 136 | * @covers \eZ\Publish\API\Repository\LanguageService::createLanguage |
||
| 137 | */ |
||
| 138 | public function testCreateLanguageThrowsInvalidArgumentException() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Test service method for updating language name. |
||
| 151 | * |
||
| 152 | * @covers \eZ\Publish\API\Repository\LanguageService::updateLanguageName |
||
| 153 | */ |
||
| 154 | public function testUpdateLanguageName() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Test service method for updating language name throwing InvalidArgumentException. |
||
| 178 | * |
||
| 179 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 180 | * @covers \eZ\Publish\API\Repository\LanguageService::updateLanguageName |
||
| 181 | */ |
||
| 182 | public function testUpdateLanguageNameThrowsInvalidArgumentException() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Test service method for enabling language. |
||
| 192 | * |
||
| 193 | * @covers \eZ\Publish\API\Repository\LanguageService::enableLanguage |
||
| 194 | */ |
||
| 195 | public function testEnableLanguage() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Test service method for disabling language. |
||
| 231 | * |
||
| 232 | * @covers \eZ\Publish\API\Repository\LanguageService::disableLanguage |
||
| 233 | */ |
||
| 234 | public function testDisableLanguage() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Test service method for loading language. |
||
| 258 | * |
||
| 259 | * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage |
||
| 260 | */ |
||
| 261 | View Code Duplication | public function testLoadLanguage() |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Test service method for loading language throwing InvalidArgumentException. |
||
| 280 | * |
||
| 281 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 282 | * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage |
||
| 283 | */ |
||
| 284 | public function testLoadLanguageThrowsInvalidArgumentException() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Test service function for loading language throwing NotFoundException. |
||
| 291 | * |
||
| 292 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 293 | * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage |
||
| 294 | */ |
||
| 295 | public function testLoadLanguageThrowsNotFoundException() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Test service method for loading all languages. |
||
| 302 | * |
||
| 303 | * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguages |
||
| 304 | */ |
||
| 305 | public function testLoadLanguages() |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Test service method for loading language by ID. |
||
| 321 | * |
||
| 322 | * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageById |
||
| 323 | */ |
||
| 324 | View Code Duplication | public function testLoadLanguageById() |
|
| 340 | |||
| 341 | /** |
||
| 342 | * Test service method for loading language by ID throwing NotFoundException. |
||
| 343 | * |
||
| 344 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 345 | * @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageById |
||
| 346 | */ |
||
| 347 | public function testLoadLanguageByIdThrowsNotFoundException() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Test service method for deleting language. |
||
| 354 | * |
||
| 355 | * @covers \eZ\Publish\API\Repository\LanguageService::deleteLanguage |
||
| 356 | */ |
||
| 357 | View Code Duplication | public function testDeleteLanguage() |
|
| 374 | |||
| 375 | /** |
||
| 376 | * Test service method for deleting language throwing InvalidArgumentException. |
||
| 377 | * |
||
| 378 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 379 | * @covers \eZ\Publish\API\Repository\LanguageService::deleteLanguage |
||
| 380 | */ |
||
| 381 | public function testDeleteLanguageThrowsInvalidArgumentException() |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Test service method for fetching the default language code. |
||
| 391 | * |
||
| 392 | * @covers \eZ\Publish\API\Repository\LanguageService::getDefaultLanguageCode |
||
| 393 | */ |
||
| 394 | public function testGetDefaultLanguageCode() |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Test service method for creating a new language create struct object. |
||
| 403 | * |
||
| 404 | * @covers \eZ\Publish\API\Repository\LanguageService::newLanguageCreateStruct |
||
| 405 | */ |
||
| 406 | public function testNewLanguageCreateStruct() |
||
| 421 | } |
||
| 422 |
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.