| Conditions | 3 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 41 | protected function field(Field $field): string |
||
| 42 | { |
||
| 43 | $relations = explode('.', $field->getName()); |
||
| 44 | $fieldValue = array_pop($relations); |
||
| 45 | |||
| 46 | foreach ($relations as $relation) { |
||
| 47 | $alias = $this->createAlias($relation); |
||
| 48 | } |
||
| 49 | |||
| 50 | if (isset($alias)) { |
||
| 51 | return $alias.'.'.$fieldValue; |
||
| 52 | } |
||
| 53 | |||
| 54 | return parent::field($field); |
||
| 55 | } |
||
| 56 | |||
| 67 |
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: