Conditions | 6 |
Paths | 11 |
Total Lines | 19 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 6.1666 |
Changes | 0 |
1 | <?php |
||
24 | 4 | public function assert($data) |
|
25 | { |
||
26 | 4 | if (is_string($this->rule)) { |
|
27 | 1 | if (!tester($this->rule)->test($data)) { |
|
28 | 1 | throw new InvalidValueException([$this->rule]); |
|
29 | } |
||
30 | } |
||
31 | 3 | if ($this->rule instanceof TesterInterface) { |
|
32 | if (!$this->rule->test($data)) { |
||
33 | throw new InvalidValueException([get_class($this->rule)]); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | 3 | $errorBag = new ErrorBag(); |
|
38 | 3 | $this->rule->define(new AssertRuleDefinition($errorBag, $data)); |
|
|
|||
39 | 3 | if (count($errorBag)) { |
|
40 | 2 | throw new InvalidValueException($errorBag->errors()); |
|
41 | } |
||
42 | 3 | } |
|
43 | |||
57 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: