1 | <?php |
||
14 | class ResetCommand extends Command |
||
15 | { |
||
16 | /** |
||
17 | * Command name |
||
18 | * @var string |
||
19 | */ |
||
20 | const NAME = 'reset'; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | public function configure() |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function execute(InputInterface $input, OutputInterface $output) |
||
45 | } |
||
46 |
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: