| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 33 | { |
||
| 34 | $locator = $this->getApplication()->getLocator(); |
||
|
|
|||
| 35 | $exitStatus = 0; |
||
| 36 | |||
| 37 | foreach ($input->getArgument('commands') as $command) { |
||
| 38 | $location = $locator->locate($command); |
||
| 39 | |||
| 40 | if ($location === null) { |
||
| 41 | $output->writeln("<error>{$command} not found</error>"); |
||
| 42 | $exitStatus = 1; |
||
| 43 | } else { |
||
| 44 | $output->writeln($location); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | return $exitStatus; |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
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: