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 |
||
10 | class CheckPromocodeValidationTest extends TestCase |
||
11 | { |
||
12 | /** @test */ |
||
13 | public function it_throws_exception_if_there_is_not_such_promocode() |
||
19 | |||
20 | /** @test */ |
||
21 | public function it_returns_false_if_promocode_is_expired() |
||
36 | |||
37 | /** @test */ |
||
38 | public function it_returns_false_if_promocode_is_disposable_and_used() |
||
58 | |||
59 | /** @test */ |
||
60 | View Code Duplication | public function it_returns_promocode_model_if_validation_passes() |
|
|
|||
61 | { |
||
62 | $promocodes = Promocodes::create(); |
||
63 | $promocode = $promocodes->first(); |
||
64 | |||
65 | $this->assertCount(1, $promocodes); |
||
66 | |||
67 | $checkPromocode = Promocodes::check($promocode['code']); |
||
68 | |||
69 | $this->assertTrue($checkPromocode instanceof Promocode); |
||
70 | $this->assertEquals($promocode['code'], $checkPromocode->code); |
||
73 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.