| 1 | <?php |
||
| 12 | class MoneyFormat extends AbstractHelper |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @param Money $money |
||
| 16 | * @param bool $showDecimals |
||
| 17 | * @param string $locale |
||
| 18 | * @param string $pattern |
||
| 19 | * |
||
| 20 | * @return string |
||
| 21 | */ |
||
| 22 | public function __invoke(Money $money, $showDecimals = null, $locale = null, $pattern = null) |
||
| 28 | } |
||
| 29 |
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: