| 1 | <?php |
||
| 20 | class OrderByProcessor extends CriterionProcessor |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var int |
||
| 24 | */ |
||
| 25 | private static $relationId = 0; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param QueryBuilder $builder |
||
| 29 | * @param CriterionInterface|OrderBy $orderBy |
||
| 30 | * @return QueryBuilder |
||
| 31 | */ |
||
| 32 | public function apply(QueryBuilder $builder, CriterionInterface $orderBy): QueryBuilder |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param Field $field |
||
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | protected function field(Field $field): string |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $class |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | private function createAlias(string $class): string |
||
| 66 | } |
||
| 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: