| Conditions | 3 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | protected function postDehydrate(array &$data) |
||
| 11 | { |
||
| 12 | parent::postDehydrate($data); |
||
| 13 | |||
| 14 | if (false === in_array(CustomFieldsTrait::class, class_uses($this))) |
||
| 15 | { |
||
| 16 | return; |
||
| 17 | } |
||
| 18 | |||
| 19 | /** @var CustomFieldsTrait $this */ |
||
| 20 | $customFieldsKey = $this->getCustomFieldsKey(); |
||
|
|
|||
| 21 | $customFieldsCollection = $this->getCustomFields(); |
||
| 22 | if (null !== $customFieldsCollection) |
||
| 23 | { |
||
| 24 | $data[$customFieldsKey] = $customFieldsCollection->toArray(); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | } |
||
| 28 |
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 sub-classes 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 parent class: