| Conditions | 1 |
| Paths | 1 |
| Total Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | * @throws \Railt\Io\Exception\ExternalFileException |
||
| 27 | */ |
||
| 28 | 1 | public function resolve(RuleInterface $rule): Definition |
|
| 29 | { |
||
| 30 | 1 | $object = new ObjectDefinition($this->document, $rule->getTypeName()); |
|
| 31 | |||
| 32 | 1 | foreach ($rule->getFields() as $field) { |
|
| 33 | $object->withField($this->build($field)); |
||
| 34 | } |
||
| 35 | |||
| 36 | 1 | return $object; |
|
| 39 |
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: