| Conditions | 5 |
| Paths | 5 |
| Total Lines | 26 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 30 | public function applyCode($code, $callback = null) |
||
| 31 | { |
||
| 32 | if ($promocode = Promocodes::check($code)) { |
||
| 33 | if ($promocode->users()->wherePivot('user_id', $this->id)->exists()) { |
||
| 34 | throw new AlreadyUsedExceprion; |
||
| 35 | } |
||
| 36 | |||
| 37 | $promocode->users()->attach($this->id, [ |
||
| 38 | 'used_at' => Carbon::now(), |
||
| 39 | ]); |
||
| 40 | |||
| 41 | $promocode->load('users'); |
||
| 42 | |||
| 43 | if (is_callable($callback)) { |
||
| 44 | $callback($promocode); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $promocode; |
||
| 48 | } |
||
| 49 | |||
| 50 | if (is_callable($callback)) { |
||
| 51 | $callback(null); |
||
| 52 | } |
||
| 53 | |||
| 54 | return null; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.