| 1 | <?php |
||
| 10 | trait FieldWithOptions |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | protected $options; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param array $options |
||
| 19 | * @return self |
||
| 20 | */ |
||
| 21 | public function withOptions($options = []) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param mixed $identifier |
||
| 32 | * @return bool |
||
| 33 | */ |
||
| 34 | public function hasOption($identifier) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param void |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | public function getOptions() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param void |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | public function getOptionsKeys() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param void |
||
| 59 | * @return string|null |
||
| 60 | */ |
||
| 61 | public function getOption($identifier) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param void |
||
| 68 | * @return string|null |
||
| 69 | */ |
||
| 70 | public function getTableValue() |
||
| 74 | } |
||
| 75 |
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.