1 | <?php declare(strict_types=1); |
||
20 | class Media extends RuleAbstract |
||
21 | { |
||
22 | const NODE_NAME = 'enclosure'; |
||
23 | |||
24 | const MRSS_NAMESPACE = "http://search.yahoo.com/mrss/"; |
||
25 | |||
26 | protected $urlAttributeName = 'url'; |
||
27 | |||
28 | /** |
||
29 | * @var UrlGenerator |
||
30 | */ |
||
31 | protected $urlGenerator; |
||
32 | |||
33 | 24 | public function __construct(string $nodeName = null) |
|
38 | |||
39 | /** |
||
40 | * @return string |
||
41 | */ |
||
42 | 5 | public function getUrlAttributeName() : string |
|
46 | |||
47 | /** |
||
48 | * @param string $name |
||
49 | */ |
||
50 | 12 | public function setUrlAttributeName(string $name) : void |
|
54 | |||
55 | /** |
||
56 | * @param NodeInterface $node |
||
57 | * @param \DOMElement $element |
||
58 | */ |
||
59 | 5 | public function setProperty(NodeInterface $node, \DOMElement $element) : void |
|
84 | |||
85 | /** |
||
86 | * @param MediaInterface $media |
||
87 | * @param string $url |
||
88 | * @param NodeInterface $node |
||
89 | */ |
||
90 | 5 | protected function setUrl(MediaInterface $media, string $url, NodeInterface $node): void |
|
94 | |||
95 | /** |
||
96 | * @param \DomDocument $document |
||
97 | * @param MediaInterface $media |
||
98 | * @return \DomElement |
||
99 | */ |
||
100 | 1 | public function createMediaElement(\DomDocument $document, MediaInterface $media) : \DOMElement |
|
109 | |||
110 | /** |
||
111 | * @param \MediaInterface $media |
||
112 | * @param \DomElement $element |
||
113 | */ |
||
114 | 1 | protected function initMedia(MediaInterface $media, \DOMElement $element): void |
|
120 | |||
121 | /** |
||
122 | * @inheritDoc |
||
123 | */ |
||
124 | 5 | protected function hasValue(NodeInterface $node) : bool |
|
128 | |||
129 | /** |
||
130 | * @inheritDoc |
||
131 | */ |
||
132 | 5 | protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
138 | } |
||
139 |
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: