1 | <?php declare(strict_types=1); |
||
30 | class XmlParser extends ParserAbstract |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * @param $tagName |
||
35 | * @return bool |
||
36 | */ |
||
37 | 12 | public function isItem(string $tagName) : bool |
|
41 | |||
42 | /** |
||
43 | * @param Document $document |
||
44 | * @param FeedInterface $feed |
||
45 | * @return \FeedIo\FeedInterface |
||
46 | * @throws Parser\MissingFieldsException |
||
47 | * @throws Parser\UnsupportedFormatException |
||
48 | */ |
||
49 | 12 | public function parseContent(Document $document, FeedInterface $feed) : FeedInterface |
|
57 | |||
58 | /** |
||
59 | * @param Document $document |
||
60 | * @param iterable $mandatoryFields |
||
61 | * @throws MissingFieldsException |
||
62 | * @return bool |
||
63 | */ |
||
64 | 15 | public function checkBodyStructure(Document $document, iterable $mandatoryFields) : bool |
|
84 | |||
85 | /** |
||
86 | * @param NodeInterface $item |
||
87 | * @param \DOMElement $element |
||
88 | * @param RuleSet $ruleSet |
||
89 | * @return NodeInterface |
||
90 | */ |
||
91 | 13 | public function parseNode(NodeInterface $item, \DOMElement $element, RuleSet $ruleSet) : NodeInterface |
|
101 | |||
102 | /** |
||
103 | * @param NodeInterface $item |
||
104 | * @param \DOMElement $node |
||
105 | * @param RuleSet $ruleSet |
||
106 | */ |
||
107 | 12 | protected function handleNode(NodeInterface $item, \DOMElement $node, RuleSet $ruleSet) : void |
|
117 | } |
||
118 |
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: