1 | <?php |
||
15 | class SortProcessor implements ProcessorInterface |
||
16 | { |
||
17 | /** |
||
18 | * Applies operation to data source and returns modified data source. |
||
19 | * |
||
20 | * @param QueryBuilder $src |
||
21 | * @param OperationInterface|SortOperation $operation |
||
22 | * @return QueryBuilder |
||
23 | */ |
||
24 | public function process($src, OperationInterface $operation) |
||
31 | } |
||
32 |
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: