| Conditions | 5 |
| Paths | 5 |
| Total Lines | 17 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 11 | public function resolveByContainer($ref, ContainerInterface $container, $expectedClass) |
|
| 21 | { |
||
| 22 | try { |
||
| 23 | 11 | $entry = $container->get($ref); |
|
|
|
|||
| 24 | 11 | } catch (NotFoundExceptionInterface $e) { |
|
| 25 | 2 | throw new UnresolvedException('Could not found an entry from the container.', 0, $e); |
|
| 26 | 2 | } catch (ContainerExceptionInterface $e) { |
|
| 27 | 2 | throw new UnresolvedException('Something wrong with the container.', 0, $e); |
|
| 28 | } |
||
| 29 | |||
| 30 | 7 | if (!$entry instanceof $expectedClass) { |
|
| 31 | 2 | $type = is_object($entry) ? get_class($entry) : gettype($entry); |
|
| 32 | 2 | throw new UnresolvedException("Expected container returns an instance of {$expectedClass}, {$type} given."); |
|
| 33 | } |
||
| 34 | |||
| 35 | 5 | return $entry; |
|
| 36 | } |
||
| 37 | } |
||
| 38 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: