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 NodeInterface $node |
||
88 | * @param string|null $url |
||
89 | */ |
||
90 | 5 | protected function setUrl(MediaInterface $media, NodeInterface $node, string $url = null): void |
|
98 | |||
99 | /** |
||
100 | * @param \DomDocument $document |
||
101 | * @param MediaInterface $media |
||
102 | * @return \DomElement |
||
103 | */ |
||
104 | 1 | public function createMediaElement(\DomDocument $document, MediaInterface $media) : \DOMElement |
|
113 | |||
114 | /** |
||
115 | * @param MediaInterface $media |
||
116 | * @param \DomElement $element |
||
117 | */ |
||
118 | 1 | protected function initMedia(MediaInterface $media, \DOMElement $element): void |
|
124 | |||
125 | /** |
||
126 | * @inheritDoc |
||
127 | */ |
||
128 | 5 | protected function hasValue(NodeInterface $node) : bool |
|
132 | |||
133 | /** |
||
134 | * @inheritDoc |
||
135 | */ |
||
136 | 5 | protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
142 | } |
||
143 |
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: