1 | <?php |
||
16 | class SimpleConditionBuilder implements ExpressionBuilderInterface |
||
17 | { |
||
18 | use ExpressionBuilderTrait; |
||
19 | |||
20 | /** |
||
21 | * Method builds the raw SQL from the $expression that will not be additionally |
||
22 | * escaped or quoted. |
||
23 | * |
||
24 | * @param ExpressionInterface|SimpleCondition $expression the expression to be built. |
||
25 | * @param array $params the binding parameters. |
||
26 | * @return string the raw SQL that will not be additionally escaped or quoted. |
||
27 | */ |
||
28 | 84 | public function build(ExpressionInterface $expression, array &$params = []) |
|
48 | } |
||
49 |
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: