1 | <?php |
||
26 | class Command extends BaseCommand |
||
27 | { |
||
28 | /** |
||
29 | * Registers the current command. |
||
30 | * |
||
31 | * @param HelperSet $helperSet |
||
32 | */ |
||
33 | 1 | public function setHelperSet(HelperSet $helperSet) |
|
39 | |||
40 | /** |
||
41 | * Returns the Progress bar helper. |
||
42 | * |
||
43 | * With this helper it is possible to display a progress bar and make it fill. |
||
44 | * |
||
45 | * @param InputInterface $input |
||
46 | * |
||
47 | * @return ProgressHelper |
||
48 | */ |
||
49 | 2 | protected function getProgressBar(InputInterface $input) |
|
57 | } |
||
58 |
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: