| 1 | <?php |
||
| 12 | class EntityUtils |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @deprecated |
||
| 16 | */ |
||
| 17 | public const VALID_UUID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param EntityInterface[] $entities |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | */ |
||
| 24 | 2 | public static function collectIds(array $entities): array |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @param $id |
||
| 36 | * |
||
| 37 | * @return bool |
||
| 38 | * @deprecated Use Ramsey\Uuid::isValid instead |
||
| 39 | * |
||
| 40 | */ |
||
| 41 | 2 | public static function isUuid($id): bool |
|
| 45 | } |
||
| 46 |
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: