| 1 | <?php  | 
            ||
| 5 | trait StringGenerator  | 
            ||
| 6 | { | 
            ||
| 7 | /**  | 
            ||
| 8 | * Generate a random string.  | 
            ||
| 9 | *  | 
            ||
| 10 | * @param \Closure $generator  | 
            ||
| 11 | * @return mixed  | 
            ||
| 12 | */  | 
            ||
| 13 | 10 | protected function generateString($generator)  | 
            |
| 23 | |||
| 24 | /**  | 
            ||
| 25 | * Get the alpha generator.  | 
            ||
| 26 | *  | 
            ||
| 27 | * @return mixed  | 
            ||
| 28 | */  | 
            ||
| 29 | protected function getAlphaGenerator()  | 
            ||
| 35 | |||
| 36 | /**  | 
            ||
| 37 | * Get the final string size.  | 
            ||
| 38 | *  | 
            ||
| 39 | * @return integer  | 
            ||
| 40 | */  | 
            ||
| 41 | 10 | public function getSize()  | 
            |
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * Set the return string size.  | 
            ||
| 48 | *  | 
            ||
| 49 | * @param $size  | 
            ||
| 50 | * @return $this  | 
            ||
| 51 | */  | 
            ||
| 52 | 10 | public function size($size)  | 
            |
| 58 | |||
| 59 | /**  | 
            ||
| 60 | * Trim string to expected size.  | 
            ||
| 61 | *  | 
            ||
| 62 | * @param $string  | 
            ||
| 63 | * @param int|null $size  | 
            ||
| 64 | * @return string  | 
            ||
| 65 | */  | 
            ||
| 66 | 10 | protected function trimToExpectedSize($string, $size = null)  | 
            |
| 70 | }  | 
            ||
| 71 | 
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.