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