Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 2.0116 |
Changes | 0 |
1 | <?php |
||
19 | 6 | public function resolve(DefinitionInterface $definition) |
|
20 | { |
||
21 | 6 | $this->validate($definition, ClassDefinition::class); |
|
22 | |||
23 | 6 | $class = $definition->getClass(); |
|
|
|||
24 | |||
25 | 6 | if (!class_exists($class)) { |
|
26 | NotFoundException::create($class); |
||
27 | } |
||
28 | |||
29 | 6 | $params = $this->getConstructorParams($class); |
|
30 | |||
31 | 6 | return new $class(...$params); |
|
32 | } |
||
33 | } |
||
34 |
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: