| Conditions | 3 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function ifExists($key) |
||
| 17 | { |
||
| 18 | $verifParams = verifTypeData([['type' => 'string', 'data' => $key]]); |
||
| 19 | if (!$verifParams) { |
||
| 20 | throw new \Exception('The $key parameters must be a string'); |
||
| 21 | } |
||
| 22 | |||
| 23 | if ($this->get($key) === false) { |
||
|
|
|||
| 24 | return false; |
||
| 25 | } |
||
| 26 | |||
| 27 | return true; |
||
| 28 | } |
||
| 29 | |||
| 64 |
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.