1 | <?php |
||
20 | class IndentedCode extends AbstractStringContainerBlock |
||
21 | { |
||
22 | /** |
||
23 | * Returns true if this block can contain the given block as a child node |
||
24 | * |
||
25 | * @param AbstractBlock $block |
||
26 | * |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function canContain(AbstractBlock $block): bool |
||
33 | |||
34 | /** |
||
35 | * Whether this is a code block |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | 75 | public function isCode(): bool |
|
43 | |||
44 | 87 | public function matchesNextLine(Cursor $cursor): bool |
|
56 | |||
57 | 150 | public function finalize(ContextInterface $context, int $endLineNumber) |
|
77 | |||
78 | /** |
||
79 | * @param ContextInterface $context |
||
80 | * @param Cursor $cursor |
||
81 | */ |
||
82 | 147 | public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
|
86 | } |
||
87 |
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: