1 | <?php |
||
27 | class UnzipAssetsCommand extends Command { |
||
28 | |||
29 | /** |
||
30 | * Command help. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | const COMMAND_HELP = <<< 'EOT' |
||
35 | The <info>%command.name%</info> command unzips bundle assets into a given |
||
36 | directory (e.g. the <comment>public</comment> directory). |
||
37 | |||
38 | <info>php %command.full_name% public</info> |
||
39 | |||
40 | EOT; |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | protected function configure() { |
||
51 | |||
52 | /** |
||
53 | * Display the footer. |
||
54 | * |
||
55 | * @param SymfonyStyle $io The I/O. |
||
56 | * @param int $exitCode The exit code. |
||
57 | * @param int $count The count. |
||
58 | * @return void |
||
59 | */ |
||
60 | protected function displayFooter(SymfonyStyle $io, $exitCode, $count) { |
||
70 | |||
71 | /** |
||
72 | * Displays the header. |
||
73 | * |
||
74 | * @param SymfonyStyle $io The I/O. |
||
75 | * @return void |
||
76 | */ |
||
77 | protected function displayHeader(SymfonyStyle $io) { |
||
82 | |||
83 | /** |
||
84 | * Displays the result. |
||
85 | * |
||
86 | * @param SymfonyStyle $io The I/O. |
||
87 | * @param array $results The results. |
||
88 | * @return int Returns the exit code. |
||
89 | */ |
||
90 | protected function displayResult(SymfonyStyle $io, array $results) { |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
164 | |||
165 | /** |
||
166 | * Create a Symfony style. |
||
167 | * |
||
168 | * @param InputInterface $input The input. |
||
169 | * @param OutputInterface $output The ouptut. |
||
170 | * @return SymfonyStyle Returns the Symfony style. |
||
171 | */ |
||
172 | protected function newSymfonyStyle(InputInterface $input, OutputInterface $output) { |
||
175 | |||
176 | } |
||
177 |
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: