Conditions | 2 |
Paths | 2 |
Total Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
27 | 14 | public function resolve(DefinitionInterface $definition) |
|
28 | { |
||
29 | 14 | $this->validate($definition, ClassDefinition::class); |
|
30 | |||
31 | 14 | $class = $definition->getClass(); |
|
|
|||
32 | 14 | $params = $this->getConstructorParams($class); |
|
33 | |||
34 | 10 | $entry = new $class(...$params); |
|
35 | |||
36 | 10 | if ($this->getContainer()->hasAnnotationsEnabled()) { |
|
37 | 1 | $this->injectProperties($entry); |
|
38 | } |
||
39 | |||
40 | 10 | return $entry; |
|
41 | } |
||
42 | } |
||
43 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: