| 1 | <?php |
||
| 9 | trait Key |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param string|int $key |
||
| 13 | * @return bool|mixed |
||
| 14 | */ |
||
| 15 | 3 | public function getKey($key) |
|
| 19 | |||
| 20 | /** |
||
| 21 | * @return array |
||
| 22 | */ |
||
| 23 | 5 | public function getKeys() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @return mixed |
||
| 30 | */ |
||
| 31 | 1 | public function getFirstKey() |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return mixed |
||
| 39 | */ |
||
| 40 | 4 | public function getLastKey() |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @param $key |
||
| 48 | * @return bool |
||
| 49 | */ |
||
| 50 | 3 | public function keyExists($key) |
|
| 54 | |||
| 55 | } |
||
| 56 |
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.