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