| 1 | <?php |
||
| 13 | trait AskAndValidate |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @param string $question |
||
| 17 | * @param string $field |
||
| 18 | * @return string |
||
| 19 | */ |
||
| 20 | protected function askWithValidation(string $question, string $field): string |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Required method to return the entity/model that contains the validation rules |
||
| 48 | * |
||
| 49 | * @return Model |
||
| 50 | */ |
||
| 51 | abstract protected function getEntity(): Model; |
||
| 52 | } |
||
| 53 |
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.