| Conditions | 7 |
| Paths | 4 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 11.8162 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | 30 | public function select(...$fields): self |
|
| 26 | { |
||
| 27 | 30 | foreach ($fields as $field) { |
|
| 28 | 30 | if (! \is_array($field) && ! \is_string($field)) { |
|
| 29 | $error = 'Selection should be array (["field" => "alias"]) or string ("field") but %s given'; |
||
| 30 | throw new \InvalidArgumentException(\sprintf($error, \gettype($field))); |
||
| 31 | } |
||
| 32 | |||
| 33 | 30 | if (\is_string($field)) { |
|
| 34 | 30 | $this->add(new Selection($this, $field)); |
|
|
|
|||
| 35 | 30 | continue; |
|
| 36 | } |
||
| 37 | |||
| 38 | foreach ($field as $name => $alias) { |
||
| 39 | if (\is_int($name)) { |
||
| 40 | [$name, $alias] = [$alias, null]; |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->add(new Selection($this, $name, $alias)); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | 30 | return $this; |
|
| 47 | } |
||
| 48 | |||
| 58 |
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.