1 | <?php |
||
12 | trait ExtendedSelectionTrait |
||
13 | { |
||
14 | use SelectionTrait; |
||
15 | |||
16 | protected $from = []; |
||
17 | protected $fields = []; |
||
18 | |||
19 | /** |
||
20 | * Adds new extra table to the query. |
||
21 | * |
||
22 | * @param string $table |
||
23 | * |
||
24 | * @return self |
||
25 | */ |
||
26 | public function from($table) |
||
32 | |||
33 | /** |
||
34 | * Adds a new extra field to the query. |
||
35 | * |
||
36 | * @param string $field |
||
37 | * |
||
38 | * @return self |
||
39 | */ |
||
40 | public function field($field) |
||
46 | |||
47 | /** |
||
48 | * Adds a WHERE according with the relation of other entity. |
||
49 | * |
||
50 | * @param RowInterface $row |
||
51 | * |
||
52 | * @return self |
||
53 | */ |
||
54 | public function relatedWith(RowInterface $row) |
||
83 | |||
84 | /** |
||
85 | * add extra fields to the code. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | protected function fieldsToString($prepend = ', ') |
||
93 | |||
94 | /** |
||
95 | * add extra fields to the code. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | protected function fromToString($prepend = ', ') |
||
103 | } |
||
104 |
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: