Conditions | 6 |
Paths | 4 |
Total Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 0 |
1 | <?php |
||
25 | public function select(...$fields): self |
||
26 | { |
||
27 | foreach ($fields as $field) { |
||
28 | 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 | if (\is_string($field)) { |
||
34 | $this->add(new Selection($field)); |
||
|
|||
35 | continue; |
||
36 | } |
||
37 | |||
38 | foreach ($field as $name => $alias) { |
||
39 | $this->add(new Selection($name, $alias)); |
||
40 | } |
||
41 | } |
||
42 | return $this; |
||
43 | } |
||
44 | } |
||
45 |
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
Idable
provides a methodequalsId
that 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.