| Conditions | 3 |
| Paths | 4 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public function build(RuleInterface $rule, Definition $parent): Definition |
||
| 30 | { |
||
| 31 | $hint = $rule->getTypeHint(); |
||
|
|
|||
| 32 | |||
| 33 | $field = new InputFieldDefinition($parent, $rule->getFieldName(), $hint->getTypeName()); |
||
| 34 | $field->withOffset($rule->getOffset()); |
||
| 35 | $field->withDescription($rule->getDescription()); |
||
| 36 | $field->withModifiers($hint->getModifiers()); |
||
| 37 | |||
| 38 | if ($default = $rule->getDefaultValue()) { |
||
| 39 | // TODO Default value |
||
| 40 | } |
||
| 41 | |||
| 42 | foreach ($rule->getDirectives() as $ast) { |
||
| 43 | $field->withDirective($this->dependent($ast, $field)); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $field; |
||
| 47 | } |
||
| 48 | } |
||
| 49 |
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: