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 NewFunctionArrayDereferencingSniffTest extends BaseSniffTest |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * testArrayDereferencing |
||
| 20 | * |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | public function testArrayDereferencing() |
||
| 24 | { |
||
| 25 | $file = $this->sniffFile('sniff-examples/new_function_array_dereferencing.php', '5.3'); |
||
| 26 | $this->assertError($file, 3, 'Function array dereferencing is not present in PHP version 5.3 or earlier'); |
||
| 27 | |||
| 28 | $file = $this->sniffFile('sniff-examples/new_function_array_dereferencing.php', '5.4'); |
||
| 29 | $this->assertNoViolation($file, 3); |
||
| 30 | } |
||
| 31 | } |
||
| 32 |