| 1 | <?php |
||
| 27 | class LanguageSwitcher extends AbstractHelper |
||
| 28 | { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $partial = 'partial/language-switcher'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * generates a select2 form with enabled languages |
||
| 37 | * |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | public function __invoke($options = []) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function getPartial() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param string $partial |
||
| 66 | * @return LanguageSwitcher |
||
| 67 | */ |
||
| 68 | public function setPartial($partial) |
||
| 74 | } |
||
| 75 |
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: