1 | <?php |
||
16 | class BetweenColumnsConditionBuilder 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|BetweenColumnsCondition $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 | 15 | public function build(ExpressionInterface $expression, array &$params = []) |
|
38 | |||
39 | /** |
||
40 | * Prepares column name to be used in SQL statement. |
||
41 | * |
||
42 | * @param Query|ExpressionInterface|string $columnName |
||
43 | * @param array $params the binding parameters. |
||
44 | * @return string |
||
45 | */ |
||
46 | 15 | protected function escapeColumnName($columnName, &$params = []) |
|
59 | |||
60 | /** |
||
61 | * Attaches $value to $params array and returns placeholder. |
||
62 | * |
||
63 | * @param mixed $value |
||
64 | * @param array $params passed by reference |
||
65 | * @return string |
||
66 | */ |
||
67 | 15 | protected function createPlaceholder($value, &$params) |
|
75 | } |
||
76 |
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: