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 |
||
| 6 | class FieldTest extends TestCase |
||
|
|
|||
| 7 | {
|
||
| 8 | |||
| 9 | /** |
||
| 10 | * @expectedException Radowoj\Yaah\Exception |
||
| 11 | * @expectedExceptionMessage fid must be an integer |
||
| 12 | */ |
||
| 13 | public function testNonIntegerFid() |
||
| 17 | |||
| 18 | |||
| 19 | /** |
||
| 20 | * Tests that output of Field->toArray() has the exact keys expected by WebAPI |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | public function testReturnedArray() |
||
| 50 | |||
| 51 | |||
| 52 | View Code Duplication | public function testStringValue() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Tests integer value representation |
||
| 64 | * @return void |
||
| 65 | */ |
||
| 66 | View Code Duplication | public function testIntegerValue() |
|
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * Tests float value representation |
||
| 78 | * @return void |
||
| 79 | */ |
||
| 80 | View Code Duplication | public function testFloatValue() |
|
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * Tests date value representation |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function testDateValue() |
|
| 102 | |||
| 103 | |||
| 104 | /** |
||
| 105 | * Test forced value type - datetime |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function testDatetimeValue() |
|
| 116 | |||
| 117 | /** |
||
| 118 | * @expectedException Radowoj\Yaah\Exception |
||
| 119 | * @expectedExceptionMessage Not supported value type: object; fid=1 |
||
| 120 | */ |
||
| 121 | public function testExceptionOnInvalidValue() |
||
| 125 | |||
| 126 | |||
| 127 | /** |
||
| 128 | * @expectedException Radowoj\Yaah\Exception |
||
| 129 | * @expectedExceptionMessage Class Radowoj\Yaah\Field does not have property: fvalueUnicorn |
||
| 130 | */ |
||
| 131 | public function testExceptionOnInvalidForcedValue() |
||
| 135 | |||
| 136 | |||
| 137 | /** |
||
| 138 | * Test fid value |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | public function testFid() |
||
| 146 | |||
| 147 | } |
||
| 148 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.