1 | <?php |
||
14 | class OneToManyReader implements CountableReader |
||
15 | { |
||
16 | /** |
||
17 | * @var Reader |
||
18 | */ |
||
19 | protected $leftReader; |
||
20 | |||
21 | /** |
||
22 | * @var Reader |
||
23 | */ |
||
24 | protected $rightReader; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $leftJoinField; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $rightJoinField; |
||
35 | |||
36 | /** |
||
37 | * Key to nest the rightRows under |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $nestKey; |
||
42 | |||
43 | /** |
||
44 | * @param Reader $leftReader |
||
45 | * @param Reader $rightReader |
||
46 | * @param string $nestKey |
||
47 | * @param string $leftJoinField |
||
48 | * @param string $rightJoinField |
||
49 | */ |
||
50 | 9 | public function __construct( |
|
67 | |||
68 | /** |
||
69 | * Create an array of children in the leftRow, |
||
70 | * with the data returned from the right reader |
||
71 | * Where the ID fields Match |
||
72 | * |
||
73 | * @return array |
||
74 | * |
||
75 | * @throws ReaderException |
||
76 | */ |
||
77 | 7 | public function current() |
|
110 | |||
111 | /** |
||
112 | * @param array $row |
||
113 | * @param string $idField |
||
114 | * |
||
115 | * @return mixed |
||
116 | * |
||
117 | * @throws ReaderException |
||
118 | */ |
||
119 | 6 | protected function getRowId(array $row, $idField) |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 4 | public function next() |
|
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | 3 | public function key() |
|
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | 4 | public function valid() |
|
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | 7 | public function rewind() |
|
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | 1 | public function getFields() |
|
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | 1 | public function count() |
|
183 | } |
||
184 |
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: