Conditions | 1 |
Paths | 1 |
Total Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
29 | public function build(Readable $file, RuleInterface $ast) |
||
30 | { |
||
31 | $field = new TypeDefinition($ast->getFullName()); |
||
|
|||
32 | $field->in($file, $ast->getOffset()); |
||
33 | |||
34 | $field->type = Type::FIELD; |
||
35 | $field->description = $ast->getDescription(); |
||
36 | |||
37 | $field->modifiers = $ast->getHintModifiers(); |
||
38 | $field->hint = $ast->getHintTypeName(); |
||
39 | |||
40 | yield from $this->loadArguments($ast, $field); |
||
41 | |||
42 | return $field; |
||
43 | } |
||
44 | |||
59 |
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: