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 SectionBase extends BaseServiceTest |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Test a new class and default values on properties. |
||
| 25 | * |
||
| 26 | * @covers \eZ\Publish\API\Repository\Values\Content\Section::__construct |
||
| 27 | */ |
||
| 28 | public function testNewClass() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Test retrieving missing property. |
||
| 44 | * |
||
| 45 | * @covers \eZ\Publish\API\Repository\Values\Content\Section::__get |
||
| 46 | */ |
||
| 47 | public function testMissingProperty() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Test setting read only property. |
||
| 59 | * |
||
| 60 | * @covers \eZ\Publish\API\Repository\Values\Content\Section::__set |
||
| 61 | */ |
||
| 62 | public function testReadOnlyProperty() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Test if property exists. |
||
| 74 | * |
||
| 75 | * @covers \eZ\Publish\API\Repository\Values\Content\Section::__isset |
||
| 76 | */ |
||
| 77 | public function testIsPropertySet() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Test unsetting a property. |
||
| 89 | * |
||
| 90 | * @covers \eZ\Publish\API\Repository\Values\Content\Section::__unset |
||
| 91 | */ |
||
| 92 | public function testUnsetProperty() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Test service function for creating sections. |
||
| 104 | * |
||
| 105 | * @covers \eZ\Publish\Core\Repository\SectionService::createSection |
||
| 106 | */ |
||
| 107 | View Code Duplication | public function testCreateSection() |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Test service function for creating sections throwing InvalidArgumentException. |
||
| 128 | * |
||
| 129 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 130 | * @covers \eZ\Publish\Core\Repository\SectionService::createSection |
||
| 131 | */ |
||
| 132 | public function testCreateSectionThrowsInvalidArgumentException() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Test service function for updating sections. |
||
| 145 | * |
||
| 146 | * @covers \eZ\Publish\Core\Repository\SectionService::updateSection |
||
| 147 | */ |
||
| 148 | View Code Duplication | public function testUpdateSection() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Test service function for updating sections. |
||
| 170 | * |
||
| 171 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 172 | * @covers \eZ\Publish\Core\Repository\SectionService::updateSection |
||
| 173 | */ |
||
| 174 | public function testUpdateSectionThrowsInvalidArgumentException() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Test service function for loading sections. |
||
| 189 | * |
||
| 190 | * @covers \eZ\Publish\Core\Repository\SectionService::loadSection |
||
| 191 | */ |
||
| 192 | View Code Duplication | public function testLoadSection() |
|
| 207 | |||
| 208 | /** |
||
| 209 | * Test service function for loading sections throwing NotFoundException. |
||
| 210 | * |
||
| 211 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 212 | * @covers \eZ\Publish\Core\Repository\SectionService::loadSection |
||
| 213 | */ |
||
| 214 | public function testLoadSectionThrowsNotFoundException() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Test service function for loading all sections. |
||
| 223 | * |
||
| 224 | * @covers \eZ\Publish\Core\Repository\SectionService::loadSections |
||
| 225 | */ |
||
| 226 | public function testLoadSections() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Test service function for loading section by identifier. |
||
| 240 | * |
||
| 241 | * @covers \eZ\Publish\Core\Repository\SectionService::loadSectionByIdentifier |
||
| 242 | */ |
||
| 243 | View Code Duplication | public function testLoadSectionByIdentifier() |
|
| 258 | |||
| 259 | /** |
||
| 260 | * Test service function for loading section by identifier throwing NotFoundException. |
||
| 261 | * |
||
| 262 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 263 | * @covers \eZ\Publish\Core\Repository\SectionService::loadSectionByIdentifier |
||
| 264 | */ |
||
| 265 | public function testLoadSectionByIdentifierThrowsNotFoundException() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Test service function for counting content assigned to section. |
||
| 274 | * |
||
| 275 | * @covers \eZ\Publish\Core\Repository\SectionService::countAssignedContents |
||
| 276 | */ |
||
| 277 | public function testCountAssignedContents() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Test service function for assigning section to content. |
||
| 298 | * |
||
| 299 | * @covers \eZ\Publish\Core\Repository\SectionService::assignSection |
||
| 300 | */ |
||
| 301 | View Code Duplication | public function testAssignSection() |
|
| 317 | |||
| 318 | /** |
||
| 319 | * Test service function for deleting sections. |
||
| 320 | * |
||
| 321 | * @covers \eZ\Publish\Core\Repository\SectionService::deleteSection |
||
| 322 | */ |
||
| 323 | View Code Duplication | public function testDeleteSection() |
|
| 341 | |||
| 342 | /** |
||
| 343 | * Test service function for deleting sections throwing NotFoundException. |
||
| 344 | * |
||
| 345 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 346 | * @covers \eZ\Publish\Core\Repository\SectionService::deleteSection |
||
| 347 | */ |
||
| 348 | public function testDeleteSectionThrowsNotFoundException() |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Test service function for deleting sections throwing BadStateException. |
||
| 359 | * |
||
| 360 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 361 | * @covers \eZ\Publish\Core\Repository\SectionService::deleteSection |
||
| 362 | */ |
||
| 363 | public function testDeleteSectionThrowsBadStateException() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Test service function for creating new SectionCreateStruct. |
||
| 374 | * |
||
| 375 | * @covers \eZ\Publish\Core\Repository\SectionService::newSectionCreateStruct |
||
| 376 | */ |
||
| 377 | View Code Duplication | public function testNewSectionCreateStruct() |
|
| 393 | |||
| 394 | /** |
||
| 395 | * Test service function for creating new SectionUpdateStruct. |
||
| 396 | * |
||
| 397 | * @covers \eZ\Publish\Core\Repository\SectionService::newSectionUpdateStruct |
||
| 398 | */ |
||
| 399 | View Code Duplication | public function testNewSectionUpdateStruct() |
|
| 415 | } |
||
| 416 |
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.