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 |
||
| 9 | class LengthTest extends TestCase |
||
| 10 | { |
||
| 11 | public function test_it_can_validate_min_length() |
||
| 12 | { |
||
| 13 | self::expectException(InvalidPassword::class); |
||
| 14 | |||
| 15 | $length = new Length(10); |
||
| 16 | |||
| 17 | $length('sõês é~i!'); |
||
| 18 | } |
||
| 19 | |||
| 20 | public function test_it_can_validate_max_length() |
||
| 21 | { |
||
| 22 | self::expectException(InvalidPassword::class); |
||
| 23 | |||
| 24 | $length = new Length(1, 6); |
||
| 25 | |||
| 26 | $length('õês é~!'); |
||
| 27 | } |
||
| 28 | } |
||
| 29 |