1 | <?php |
||
11 | class ListCommand extends AbstractMagentoCommand |
||
12 | { |
||
13 | /** |
||
14 | * @var \Magento\Search\Model\Adminhtml\System\Config\Source\Engine |
||
15 | */ |
||
16 | private $searchEngineConfig; |
||
17 | |||
18 | protected function configure() |
||
19 | { |
||
20 | $this |
||
21 | ->setName('search:engine:list') |
||
22 | ->setDescription('Lists all registered search engines') |
||
23 | ->addOption( |
||
24 | 'format', |
||
25 | null, |
||
26 | InputOption::VALUE_OPTIONAL, |
||
27 | 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']' |
||
28 | ) |
||
29 | ; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param \Magento\Search\Model\Adminhtml\System\Config\Source\Engine $searchEngineConfig |
||
34 | */ |
||
35 | public function inject(\Magento\Search\Model\Adminhtml\System\Config\Source\Engine $searchEngineConfig) |
||
39 | |||
40 | /** |
||
41 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
42 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
43 | * @return int|void |
||
44 | */ |
||
45 | protected function execute(InputInterface $input, OutputInterface $output) |
||
65 | } |
||
66 |
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: