1 | <?php |
||
11 | abstract class AbstractResponseGenerator extends AbstractCodeGenerator { |
||
12 | |||
13 | 2 | protected function getTemplateFolder() { |
|
14 | 2 | return 'response'; |
|
15 | } |
||
16 | |||
17 | /** |
||
18 | * Generates a response class for the given action |
||
19 | * |
||
20 | * @param ActionSchema $action |
||
21 | * @return PhpClass |
||
22 | */ |
||
23 | abstract public function generate(ActionSchema $action); |
||
24 | |||
25 | /** |
||
26 | * Generates a response class for the given action |
||
27 | * |
||
28 | * @param ActionSchema $action |
||
29 | * @param string $format |
||
30 | * @return AbstractPhpStruct |
||
31 | */ |
||
32 | 5 | protected function doGenerate(ActionSchema $action, $format) { |
|
42 | |||
43 | /** |
||
44 | * Generates the struct |
||
45 | * |
||
46 | * @param ActionSchema $action |
||
47 | * @param string $format |
||
48 | * @return AbstractPhpStruct |
||
49 | */ |
||
50 | 5 | protected function generateStruct(ActionSchema $action, $format) { |
|
56 | |||
57 | 5 | protected function generateRunMethod($body = '') { |
|
65 | |||
66 | 5 | protected function ensureUseStatements(AbstractPhpStruct $struct) { |
|
71 | |||
72 | } |
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: