Conditions | 2 |
Paths | 2 |
Total Lines | 16 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
24 | public static function byFieldIDAndMaterialID( |
||
25 | QueryInterface $query, |
||
26 | $materialID, |
||
27 | $fieldID, |
||
28 | self & $return = null, |
||
29 | $locale = DEFAULT_LOCALE |
||
30 | ) { |
||
31 | $return = $query->className(__CLASS__) |
||
|
|||
32 | ->cond('MaterialID', $materialID) |
||
33 | ->cond('FieldID', $fieldID) |
||
34 | ->cond('locale', $locale) |
||
35 | ->first(); |
||
36 | |||
37 | // If only one argument is passed - return null, otherwise bool |
||
38 | return func_num_args() > 1 ? $return == null : $return; |
||
39 | } |
||
40 | } |
||
41 |
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: