| 1 | <?php |
||
| 19 | class MenuFactory extends WidgetFactory |
||
| 20 | { |
||
| 21 | /** @var ManiaScriptFactory */ |
||
| 22 | protected $menuScriptFactory; |
||
| 23 | |||
| 24 | /** @var AdminGroups */ |
||
| 25 | protected $adminGroupsHelper; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param ManiaScriptFactory $menuScriptFactory |
||
| 29 | */ |
||
| 30 | public function setMenuScriptFactory($menuScriptFactory) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param AdminGroups $adminGroupsHelper |
||
| 37 | */ |
||
| 38 | public function setAdminGroupsHelper($adminGroupsHelper) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param Widget $manialink |
||
| 45 | */ |
||
| 46 | protected function createContent(ManialinkInterface $manialink) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param Widget $manialink |
||
| 58 | */ |
||
| 59 | protected function updateContent(ManialinkInterface $manialink) |
||
| 63 | |||
| 64 | } |
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: