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 SpecialCharacterTest extends TestCase |
||
| 10 | { |
||
| 11 | public function test_it_can_validate_at_least_one_special_letter() |
||
| 12 | { |
||
| 13 | self::expectException(InvalidPassword::class); |
||
| 14 | |||
| 15 | $special = new SpecialCharacter(); |
||
| 16 | |||
| 17 | $special('nospecial'); |
||
| 18 | } |
||
| 19 | |||
| 20 | public function test_it_can_validate_at_least_two_special_letters() |
||
| 21 | { |
||
| 22 | self::expectException(InvalidPassword::class); |
||
| 23 | |||
| 24 | $special = new SpecialCharacter(2); |
||
| 25 | |||
| 26 | $special('onespecial!'); |
||
| 27 | } |
||
| 28 | } |
||
| 29 |