1 | <?php |
||
11 | class EndpointCommand extends AbstractScaffoldingCommand |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $type = 'endpoint'; |
||
17 | |||
18 | /** |
||
19 | * Execute command |
||
20 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
21 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
22 | * @return void |
||
23 | */ |
||
24 | protected function execute(InputInterface $input, OutputInterface $output) |
||
28 | |||
29 | /** |
||
30 | * File Template |
||
31 | * @param string $namespace |
||
32 | * @param string $name |
||
33 | * @param string $topNSPart |
||
34 | * @return string |
||
35 | */ |
||
36 | protected function template($namespace, $name, $topNSPart = "Endpoints") |
||
62 | } |
||
63 |
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: