1 | <?php |
||
8 | class Relational extends Base |
||
9 | { |
||
10 | protected $parent; |
||
11 | protected $product; |
||
12 | protected $options; |
||
13 | protected $parentOptions; |
||
14 | protected $addPrice; |
||
15 | |||
16 | public function getKey() |
||
20 | |||
21 | public function getPrice() |
||
28 | |||
29 | 4 | public function getRecursivePrice($parentProductPrice = 0, $retailPrice = false) |
|
50 | |||
51 | 6 | public function getAdjustedPrice($retailPrice = false) |
|
56 | |||
57 | 6 | public function getParentProductPrice($retailPrice = false) |
|
64 | |||
65 | |||
66 | 8 | public function getAdjustmentPrice($parentPrice) |
|
80 | |||
81 | |||
82 | public function getItemNumber() |
||
88 | |||
89 | |||
90 | public function getProductTypeId() |
||
96 | |||
97 | public function getManufacturer() |
||
103 | 7 | ||
104 | |||
105 | /** |
||
106 | * @return product |
||
107 | */ |
||
108 | public function getProduct() |
||
112 | 3 | ||
113 | 3 | /** |
|
114 | * @param $product |
||
115 | * @return self |
||
116 | */ |
||
117 | public function setProduct($product) |
||
122 | |||
123 | /** |
||
124 | 4 | * @return options |
|
125 | */ |
||
126 | 4 | public function getOptions() |
|
130 | |||
131 | public function addOption($option) |
||
137 | |||
138 | /** |
||
139 | * @param $options |
||
140 | * @return self |
||
141 | */ |
||
142 | public function setOptions($options) |
||
152 | |||
153 | /** |
||
154 | * @return parentOptions |
||
155 | */ |
||
156 | public function getParentOptions() |
||
160 | |||
161 | /** |
||
162 | * @param $parentOptions |
||
163 | * @return self |
||
164 | 3 | */ |
|
165 | public function setParentOptions($parentOptions) |
||
170 | 2 | ||
171 | public function getAddPrice($retailPrice = false) |
||
182 | |||
183 | /** |
||
184 | * @param $addPrice |
||
185 | * @return self |
||
186 | */ |
||
187 | public function setAddPrice($addPrice) |
||
192 | |||
193 | /** |
||
194 | * @return parent |
||
195 | */ |
||
196 | public function getParent() |
||
200 | 6 | ||
201 | 6 | /** |
|
202 | 6 | * @param $parent |
|
203 | * @return self |
||
204 | */ |
||
205 | public function setParent(AbstractModel $parent) |
||
211 | |||
212 | public function __toString() |
||
223 | } |
||
224 |
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 sub-classes 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 parent class: