| 1 | <?php |
||
| 7 | trait BuyableTrait |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Get the identifier of the Buyable item. |
||
| 11 | * |
||
| 12 | * @return int|string |
||
| 13 | */ |
||
| 14 | public function getBuyableIdentifier() |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Get the description or title of the Buyable item. |
||
| 21 | * |
||
| 22 | * @return string |
||
| 23 | * @throws \Exception |
||
| 24 | */ |
||
| 25 | public function getBuyableDescription() |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get the price of the Buyable item. |
||
| 32 | * |
||
| 33 | * @return float|null |
||
| 34 | * @throws \Exception |
||
| 35 | */ |
||
| 36 | public function getBuyablePrice() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Any extra fees not based on product quantity. |
||
| 43 | * |
||
| 44 | * @return float|int |
||
| 45 | */ |
||
| 46 | public function getExtraFees() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * An array of options (color, size, etc.) for this buyable item. |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | public function getOptions(): array |
||
| 60 | } |
||
| 61 |
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.