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 |
||
16 | class ContentTest extends PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | /** |
||
19 | * @covers \eZ\Publish\Core\Repository\Values\Content\Content::getProperties |
||
20 | */ |
||
21 | View Code Duplication | public function testObjectProperties() |
|
22 | { |
||
23 | $object = new Content(array('internalFields' => array())); |
||
24 | $properties = $object->attributes(); |
||
|
|||
25 | self::assertNotContains('internalFields', $properties, 'Internal property found '); |
||
26 | self::assertContains('id', $properties, 'Property not found '); |
||
27 | self::assertContains('fields', $properties, 'Property not found '); |
||
28 | self::assertContains('versionInfo', $properties, 'Property not found '); |
||
29 | self::assertContains('contentInfo', $properties, 'Property not found '); |
||
30 | |||
31 | // check for duplicates and double check existence of property |
||
32 | $propertiesHash = array(); |
||
33 | foreach ($properties as $property) { |
||
34 | if (isset($propertiesHash[$property])) { |
||
35 | self::fail("Property '{$property}' exists several times in properties list"); |
||
36 | } elseif (!isset($object->$property)) { |
||
37 | self::fail("Property '{$property}' does not exist on object, even though it was hinted to be there"); |
||
38 | } |
||
39 | $propertiesHash[$property] = 1; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Test getName method. |
||
45 | * |
||
46 | * @covers \eZ\Publish\Core\Repository\Values\Content\Content::getName |
||
47 | */ |
||
48 | public function testGetName() |
||
58 | } |
||
59 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.