| 1 | <?php  | 
            ||
| 4 | trait TerminateTrait  | 
            ||
| 5 | { | 
            ||
| 6 | /**  | 
            ||
| 7 | * @return string  | 
            ||
| 8 | */  | 
            ||
| 9 | 1 | public function join($separator)  | 
            |
| 10 |     { | 
            ||
| 11 | 1 | $arr = $this->toArray();  | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 12 | 1 | return implode($separator, $arr);  | 
            |
| 13 | }  | 
            ||
| 14 | |||
| 15 | /**  | 
            ||
| 16 | * @return int|float  | 
            ||
| 17 | */  | 
            ||
| 18 | 5 | public function sum()  | 
            |
| 22 | |||
| 23 | /**  | 
            ||
| 24 | * @return int|float  | 
            ||
| 25 | */  | 
            ||
| 26 | 1 | public function product()  | 
            |
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * @return int  | 
            ||
| 33 | */  | 
            ||
| 34 | 1 | public function count()  | 
            |
| 35 |     { | 
            ||
| 36 | 1 |         return $this->reduce('$_carry + 1', 0); | 
            |
| 37 | }  | 
            ||
| 38 | |||
| 39 | /**  | 
            ||
| 40 | * @param string|callable $fn '$_carry + $_'  | 
            ||
| 41 | * @param mixed $initial  | 
            ||
| 42 | * @return mixed  | 
            ||
| 43 | */  | 
            ||
| 44 | 8 | public function reduce($fn, $initial = null)  | 
            |
| 58 | }  | 
            ||
| 59 | 
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.