| 1 | <?php |
||
| 5 | trait AlphaGenerator |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Generate a random string. |
||
| 9 | * |
||
| 10 | * @return int|string |
||
| 11 | */ |
||
| 12 | 9 | protected function generateAlpha() |
|
| 16 | |||
| 17 | /** |
||
| 18 | * Get the alpha generator. |
||
| 19 | * |
||
| 20 | * @return mixed |
||
| 21 | */ |
||
| 22 | protected function getNumericGenerator() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Generate a numeric random value. |
||
| 31 | * |
||
| 32 | * @return int|string |
||
| 33 | */ |
||
| 34 | 3 | protected function generateNumeric() |
|
| 42 | } |
||
| 43 |
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.