1 | <?php declare(strict_types=1); |
||
19 | class Media extends RuleAbstract |
||
20 | { |
||
21 | const NODE_NAME = 'enclosure'; |
||
22 | |||
23 | const MRSS_NAMESPACE = "http://search.yahoo.com/mrss/"; |
||
24 | |||
25 | protected $urlAttributeName = 'url'; |
||
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | 5 | public function getUrlAttributeName() : string |
|
34 | |||
35 | /** |
||
36 | * @param string $name |
||
37 | */ |
||
38 | 12 | public function setUrlAttributeName(string $name) : void |
|
42 | |||
43 | /** |
||
44 | * @param NodeInterface $node |
||
45 | * @param \DOMElement $element |
||
46 | */ |
||
47 | 5 | public function setProperty(NodeInterface $node, \DOMElement $element) : void |
|
72 | |||
73 | /** |
||
74 | * @param \DomDocument $document |
||
75 | * @param MediaInterface $media |
||
76 | * @return \DomElement |
||
77 | */ |
||
78 | 1 | public function createMediaElement(\DomDocument $document, MediaInterface $media) : \DOMElement |
|
87 | |||
88 | /** |
||
89 | * @param \MediaInterface $media |
||
90 | * @param \DomElement $element |
||
91 | */ |
||
92 | 1 | protected function initMedia(MediaInterface $media, \DOMElement $element): void |
|
98 | |||
99 | /** |
||
100 | * @inheritDoc |
||
101 | */ |
||
102 | 5 | protected function hasValue(NodeInterface $node) : bool |
|
106 | |||
107 | /** |
||
108 | * @inheritDoc |
||
109 | */ |
||
110 | 5 | protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
116 | } |
||
117 |
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 implementation 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 interface: