1 | <?php |
||
9 | class WhichCommand extends SymfonyCommand |
||
10 | { |
||
11 | /** |
||
12 | * Configures the command's options. |
||
13 | * |
||
14 | * @return void |
||
15 | */ |
||
16 | protected function configure() |
||
22 | |||
23 | /** |
||
24 | * Locates the commands given as arguments. |
||
25 | * |
||
26 | * @param \Symfony\Component\Console\Input\InputInterface $input The command |
||
27 | * input. |
||
28 | * @param \Symfony\Component\Console\Output\OutputInterface $output The |
||
29 | * command output. |
||
30 | * @return int The exit status of the command. |
||
31 | */ |
||
32 | protected function execute(InputInterface $input, OutputInterface $output) |
||
50 | } |
||
51 |
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 sub-classes 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 parent class: