1 | <?php |
||
40 | abstract class AbstractSimpleImportCommand extends Command |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * Configures the current command. |
||
45 | * |
||
46 | * @return void |
||
47 | * @see \Symfony\Component\Console\Command\Command::configure() |
||
48 | */ |
||
49 | protected function configure() |
||
60 | |||
61 | /** |
||
62 | * Return's the container instance. |
||
63 | * |
||
64 | * @return \Symfony\Component\DependencyInjection\ContainerInterface The container instance |
||
65 | */ |
||
66 | protected function getContainer() |
||
70 | |||
71 | /** |
||
72 | * Executes the current command. |
||
73 | * |
||
74 | * This method is not abstract because you can use this class |
||
75 | * as a concrete class. In this case, instead of defining the |
||
76 | * execute() method, you set the code to execute by passing |
||
77 | * a Closure to the setCode() method. |
||
78 | * |
||
79 | * @param \Symfony\Component\Console\Input\InputInterface $input An InputInterface instance |
||
80 | * @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance |
||
81 | * |
||
82 | * @return null|int null or 0 if everything went fine, or an error code |
||
83 | * @throws \LogicException When this abstract method is not implemented |
||
84 | * @see \Symfony\Component\Console\Command\Command::execute() |
||
85 | */ |
||
86 | protected function execute(InputInterface $input, OutputInterface $output) |
||
95 | |||
96 | /** |
||
97 | * Finally executes the simple command. |
||
98 | * |
||
99 | * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
||
100 | * @param \Symfony\Component\Console\Input\InputInterface $input An InputInterface instance |
||
101 | * @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | abstract protected function executeSimpleCommand( |
||
110 | } |
||
111 |
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: