| Conditions | 5 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 59 | public function apply($value) |
||
| 60 | { |
||
| 61 | if (!is_object($value)) { |
||
| 62 | throw new \RuntimeException('Trying to call method of non-object'); |
||
| 63 | } |
||
| 64 | |||
| 65 | if (!method_exists($value, $this->name)) { |
||
| 66 | throw new \RuntimeException(\sprintf('Undefined method %s::%s', \get_class($value), $this->name)); |
||
| 67 | } |
||
| 68 | |||
| 69 | $method = Delegate::fromMethod($value, $this->name); |
||
| 70 | if ($method->reflection()->isPrivate() || $method->reflection()->isProtected()) { |
||
| 71 | throw new \RuntimeException( |
||
| 72 | \sprintf('Trying to call non-public method %s::%s', \get_class($value), $this->name) |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | return $method->invokeWith($this->args()); |
||
| 77 | } |
||
| 78 | } |
||
| 79 |
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: