Conditions | 4 |
Paths | 6 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 4.0092 |
Changes | 0 |
1 | <?php |
||
28 | 84 | public function build(ExpressionInterface $expression, array &$params = []) |
|
29 | { |
||
30 | 84 | $operator = $expression->getOperator(); |
|
|
|||
31 | 84 | $column = $expression->getColumn(); |
|
32 | 84 | $value = $expression->getValue(); |
|
33 | |||
34 | 84 | if (strpos($column, '(') === false) { |
|
35 | 84 | $column = $this->queryBuilder->db->quoteColumnName($column); |
|
36 | } |
||
37 | |||
38 | 84 | if ($value === null) { |
|
39 | return "$column $operator NULL"; |
||
40 | } |
||
41 | 84 | if ($value instanceof ExpressionInterface) { |
|
42 | 54 | return "$column $operator {$this->queryBuilder->buildExpression($value, $params)}"; |
|
43 | } |
||
44 | |||
45 | 30 | $phName = $this->queryBuilder->bindParam($value, $params); |
|
46 | 30 | return "$column $operator $phName"; |
|
47 | } |
||
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: