| 1 | <?php |
||
| 34 | class EeVariantProductRelationObserver extends VariantProductRelationObserver |
||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Return the row ID for the passed SKU. |
||
| 39 | * |
||
| 40 | * @param string $sku The SKU to return the row ID for |
||
| 41 | * |
||
| 42 | * @return integer The mapped row ID |
||
| 43 | * @throws \Exception Is thrown if the SKU is not mapped yet |
||
| 44 | */ |
||
| 45 | protected function mapSku($sku) |
||
| 49 | } |
||
| 50 |
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: