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 RewardableTraitTest extends TestCase |
||
|
|
|||
| 10 | { |
||
| 11 | // |
||
| 12 | public $user; |
||
| 13 | |||
| 14 | // |
||
| 15 | public function setUp(): void |
||
| 22 | |||
| 23 | /** @test */ |
||
| 24 | public function it_returns_false_if_could_not_apply_promocode() |
||
| 30 | |||
| 31 | /** @test */ |
||
| 32 | public function it_returns_null_in_callback_if_could_not_apply_promocode() |
||
| 38 | |||
| 39 | /** @test */ |
||
| 40 | View Code Duplication | public function it_can_be_user_multiple_times_if_it_is_not_disposable() |
|
| 50 | |||
| 51 | /** @test */ |
||
| 52 | public function it_returns_false_for_second_use_of_disposable_code() |
||
| 62 | |||
| 63 | /** @test */ |
||
| 64 | public function it_attaches_current_user_as_applied_to_promocode() |
||
| 79 | |||
| 80 | /** @test */ |
||
| 81 | public function is_returns_promocode_with_user_if_applied_successfuly() |
||
| 82 | { |
||
| 83 | $promocodes = Promocodes::create(); |
||
| 84 | $promocode = $promocodes->first(); |
||
| 85 | |||
| 86 | $this->assertCount(1, $promocodes); |
||
| 87 | |||
| 88 | $appliedPromocode = $this->user->applyCode($promocode['code']); |
||
| 89 | |||
| 90 | $this->assertTrue($appliedPromocode instanceof Promocode); |
||
| 91 | |||
| 92 | $this->assertCount(1, $appliedPromocode->users); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** @test */ |
||
| 96 | View Code Duplication | public function it_returns_promocode_with_user_in_callback_if_applied_successfuly() |
|
| 107 | |||
| 108 | /** @test */ |
||
| 109 | View Code Duplication | public function it_has_alias_named_reedem_code() |
|
| 120 | } |
||
| 121 |