| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function redeemCode(string $code) |
||
| 22 | { |
||
| 23 | $voucher = Vouchers::check($code); |
||
| 24 | |||
| 25 | if ($voucher->users()->wherePivot('user_id', $this->id)->exists()) { |
||
|
|
|||
| 26 | throw VoucherAlreadyRedeemed::create($voucher); |
||
| 27 | } |
||
| 28 | if ($voucher->isExpired()) { |
||
| 29 | throw VoucherExpired::create($voucher); |
||
| 30 | } |
||
| 31 | |||
| 32 | $this->vouchers()->attach($voucher, [ |
||
| 33 | 'redeemed_at' => now() |
||
| 34 | ]); |
||
| 35 | |||
| 36 | event(new VoucherRedeemed($this, $voucher)); |
||
| 37 | |||
| 38 | return $voucher; |
||
| 39 | } |
||
| 40 | |||
| 61 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: