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 |
||
| 18 | class VersionInfoTest extends ValueObjectVisitorBaseTest |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var \DateTime |
||
| 22 | */ |
||
| 23 | protected $creationDate; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var \DateTime |
||
| 27 | */ |
||
| 28 | protected $modificationDate; |
||
| 29 | |||
| 30 | public function setUp() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Test the VersionInfo visitor. |
||
| 38 | * |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | public function testVisit() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param string $result |
||
| 93 | * |
||
| 94 | * @depends testVisit |
||
| 95 | */ |
||
| 96 | public function testResultContainsVersionInfoChildren($result) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param string $result |
||
| 114 | * |
||
| 115 | * @depends testVisit |
||
| 116 | */ |
||
| 117 | public function testVersionInfoIdElement($result) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param string $result |
||
| 132 | * |
||
| 133 | * @depends testVisit |
||
| 134 | */ |
||
| 135 | public function testVersionInfoVersionNoElement($result) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $result |
||
| 150 | * |
||
| 151 | * @depends testVisit |
||
| 152 | */ |
||
| 153 | public function testVersionInfoStatusElement($result) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param string $result |
||
| 168 | * |
||
| 169 | * @depends testVisit |
||
| 170 | */ |
||
| 171 | View Code Duplication | public function testVersionInfoCreationDateElement($result) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * @param string $result |
||
| 186 | * |
||
| 187 | * @depends testVisit |
||
| 188 | */ |
||
| 189 | View Code Duplication | public function testVersionInfoModificationDateElement($result) |
|
| 201 | |||
| 202 | /** |
||
| 203 | * @param string $result |
||
| 204 | * |
||
| 205 | * @depends testVisit |
||
| 206 | */ |
||
| 207 | public function testVersionInfoInitialLanguageCodeElement($result) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param string $result |
||
| 222 | * |
||
| 223 | * @depends testVisit |
||
| 224 | */ |
||
| 225 | public function testVersionInfoLanguageCodesElement($result) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param string $result |
||
| 240 | * |
||
| 241 | * @depends testVisit |
||
| 242 | */ |
||
| 243 | public function testVersionInfoNamesElement($result) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param string $result |
||
| 261 | * |
||
| 262 | * @depends testVisit |
||
| 263 | */ |
||
| 264 | public function testVersionInfoContentElement($result) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Get the VersionInfo visitor. |
||
| 282 | * |
||
| 283 | * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\VersionInfo |
||
| 284 | */ |
||
| 285 | protected function internalGetVisitor() |
||
| 289 | } |
||
| 290 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.