| Conditions | 6 |
| Paths | 10 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function passes($attribute, $value) |
||
| 25 | { |
||
| 26 | try { |
||
| 27 | $voucher = Vouchers::check($value); |
||
| 28 | |||
| 29 | // Check if the voucher was already redeemed |
||
| 30 | if (auth()->check() && $voucher->users()->wherePivot('user_id', auth()->id())->exists()) { |
||
| 31 | throw VoucherAlreadyRedeemed::create($voucher); |
||
| 32 | } |
||
| 33 | } catch (VoucherIsInvalid $exception) { |
||
| 34 | $this->isInvalid = true; |
||
| 35 | return false; |
||
| 36 | } catch (VoucherExpired $exception) { |
||
| 37 | $this->isExpired = true; |
||
| 38 | return false; |
||
| 39 | } catch (VoucherAlreadyRedeemed $exception) { |
||
| 40 | $this->wasRedeemed = true; |
||
| 41 | return false; |
||
| 42 | } |
||
| 43 | |||
| 44 | return true; |
||
| 45 | } |
||
| 46 | |||
| 63 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: