| 1 | <?php |
||
| 12 | trait HasItemTrait |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var Record |
||
| 17 | */ |
||
| 18 | protected $item; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return Record |
||
| 22 | */ |
||
| 23 | 8 | public function getItem() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param Record|HasRelationsRecordTrait $item |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | 9 | public function setItem(Record $item) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @return mixed |
||
| 41 | */ |
||
| 42 | 2 | public function getItemRelationPrimaryKey() |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @param $key |
||
| 50 | * @return mixed |
||
| 51 | */ |
||
| 52 | 2 | public function getItemValue($key) |
|
| 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.