| Conditions | 3 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 20 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Apply promocode to user and get callback. |
||
| 23 | * |
||
| 24 | * @param string $code |
||
| 25 | * @param null|\Closure $callback |
||
| 26 | * |
||
| 27 | * @return null|\Gabievi\Promocodes\Model\Promocode |
||
| 28 | * @throws \Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion |
||
| 29 | */ |
||
| 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 | ]); |
||
| 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.