1 | <?php |
||
20 | class Paragraph extends AbstractStringContainerBlock implements InlineContainerInterface |
||
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 | 69 | public function canContain(AbstractBlock $block): bool |
|
33 | |||
34 | /** |
||
35 | * Whether this is a code block |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | 381 | public function isCode(): bool |
|
43 | |||
44 | 723 | public function matchesNextLine(Cursor $cursor): bool |
|
54 | |||
55 | 1659 | public function finalize(ContextInterface $context, int $endLineNumber) |
|
76 | |||
77 | /** |
||
78 | * @param ContextInterface $context |
||
79 | * @param Cursor $cursor |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | 426 | protected function parseReferences(ContextInterface $context, Cursor $cursor) |
|
93 | |||
94 | /** |
||
95 | * @param ContextInterface $context |
||
96 | * @param Cursor $cursor |
||
97 | */ |
||
98 | 276 | public function handleRemainingContents(ContextInterface $context, Cursor $cursor) |
|
103 | |||
104 | /** |
||
105 | * @return string[] |
||
106 | */ |
||
107 | 1698 | public function getStrings(): array |
|
111 | } |
||
112 |
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: