| Conditions | 5 |
| Paths | 4 |
| Total Lines | 13 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 18 | public function __construct($data=null, bool $strict=false) |
||
| 19 | { |
||
| 20 | if (is_array($data) || is_object($data)) { |
||
| 21 | foreach ($data as $key => $value) { |
||
| 22 | $this->setField($key, $value, $strict); |
||
|
|
|||
| 23 | } |
||
| 24 | } elseif ($data !== null) { |
||
| 25 | throw new InvalidArgumentException( |
||
| 26 | get_called_class() . |
||
| 27 | ' constructor expects array, object, or null' |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | } |
||
| 32 |
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.