Conditions | 1 |
Paths | 1 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
48 | protected function executeSql($sql, Where $condition = null) |
||
49 | { |
||
50 | $condition = (new Where())->andWhere($condition); |
||
51 | $sql = strtr($sql, ['{condition}' => $condition]); |
||
52 | |||
53 | return $this |
||
|
|||
54 | ->getSession() |
||
55 | ->getClientUsingPooler( |
||
56 | 'query_manager', |
||
57 | null |
||
58 | ) |
||
59 | ->query($sql, $condition->getValues()) |
||
60 | ; |
||
61 | } |
||
62 | } |
||
63 |
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: