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 ForbiddenNegativeBitshiftSniffTest extends BaseSniffTest |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * testSettingTestVersion |
||
| 20 | * |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | public function testSettingTestVersion() |
||
| 24 | { |
||
| 25 | $file = $this->sniffFile('sniff-examples/forbidden_negative_bitshift.php', '5.6'); |
||
| 26 | $this->assertNoViolation($file, 3); |
||
| 27 | $this->assertNoViolation($file, 5); |
||
| 28 | |||
| 29 | $file = $this->sniffFile('sniff-examples/forbidden_negative_bitshift.php', '7.0'); |
||
| 30 | $this->assertError($file, 3, 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0'); |
||
| 31 | $this->assertNoViolation($file, 5); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 |