1 | <?php |
||
26 | class UnzipAssetsCommand extends AbstractCommand { |
||
27 | |||
28 | /** |
||
29 | * Command help. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | const COMMAND_HELP = <<< 'EOT' |
||
34 | The <info>%command.name%</info> command unzips bundle assets into a given |
||
35 | directory (e.g. the <comment>public</comment> directory). |
||
36 | |||
37 | <info>php %command.full_name% public</info> |
||
38 | |||
39 | EOT; |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | protected function configure() { |
||
50 | |||
51 | /** |
||
52 | * Display the footer. |
||
53 | * |
||
54 | * @param StyleInterface $io The I/O. |
||
55 | * @param int $exitCode The exit code. |
||
56 | * @param int $count The count. |
||
57 | * @return void |
||
58 | */ |
||
59 | protected function displayFooter(StyleInterface $io, $exitCode, $count) { |
||
69 | |||
70 | /** |
||
71 | * Displays the header. |
||
72 | * |
||
73 | * @param StyleInterface $io The I/O. |
||
74 | * @return void |
||
75 | */ |
||
76 | protected function displayHeader(StyleInterface $io) { |
||
81 | |||
82 | /** |
||
83 | * Displays the result. |
||
84 | * |
||
85 | * @param StyleInterface $io The I/O. |
||
86 | * @param array $results The results. |
||
87 | * @return int Returns the exit code. |
||
88 | */ |
||
89 | protected function displayResult(StyleInterface $io, array $results) { |
||
90 | |||
91 | // Initialize. |
||
92 | $success = $this->getCheckbox(true); |
||
93 | $warning = $this->getCheckbox(false); |
||
94 | |||
95 | $rows = []; |
||
96 | |||
97 | $exitCode = 0; |
||
98 | |||
99 | // Handle each result. |
||
100 | foreach ($results as $bundle => $assets) { |
||
101 | foreach ($assets as $asset => $result) { |
||
102 | |||
103 | $rows[] = [ |
||
104 | true === $result ? $success : $warning, |
||
105 | $bundle, |
||
106 | basename($asset), |
||
107 | ]; |
||
108 | |||
109 | $exitCode += true === $result ? 0 : 1; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | // Display a table. |
||
114 | $io->table(["", "Bundle", "Asset"], $rows); |
||
115 | |||
116 | // Return the exit code. |
||
117 | return $exitCode; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
163 | |||
164 | } |
||
165 |
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: