1 | <?php |
||
21 | class InlineParserContext |
||
22 | { |
||
23 | private $container; |
||
24 | private $referenceMap; |
||
25 | private $cursor; |
||
26 | private $delimiterStack; |
||
27 | |||
28 | 1752 | public function __construct(AbstractBlock $container, ReferenceMap $referenceMap) |
|
35 | |||
36 | /** |
||
37 | * @return AbstractBlock |
||
38 | */ |
||
39 | 1293 | public function getContainer(): AbstractBlock |
|
43 | |||
44 | /** |
||
45 | * @return ReferenceMap |
||
46 | */ |
||
47 | 429 | public function getReferenceMap(): ReferenceMap |
|
51 | |||
52 | /** |
||
53 | * @return Cursor |
||
54 | */ |
||
55 | 1752 | public function getCursor(): Cursor |
|
59 | |||
60 | /** |
||
61 | * @return DelimiterStack |
||
62 | */ |
||
63 | 1743 | public function getDelimiterStack(): DelimiterStack |
|
67 | } |
||
68 |
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: