1 | <?php |
||
19 | class Media extends RuleAbstract |
||
20 | { |
||
21 | const NODE_NAME = 'enclosure'; |
||
22 | |||
23 | protected $urlAttributeName = 'url'; |
||
24 | |||
25 | /** |
||
26 | * @return string |
||
27 | */ |
||
28 | 5 | public function getUrlAttributeName() |
|
32 | |||
33 | /** |
||
34 | * @param string $name |
||
35 | * @return $this |
||
36 | */ |
||
37 | 8 | public function setUrlAttributeName($name) |
|
43 | |||
44 | /** |
||
45 | * @param NodeInterface $node |
||
46 | * @param \DOMElement $element |
||
47 | * @return $this |
||
48 | */ |
||
49 | 4 | public function setProperty(NodeInterface $node, \DOMElement $element) |
|
62 | |||
63 | /** |
||
64 | * @param \DomDocument $document |
||
65 | * @param MediaInterface $media |
||
66 | * @return \DomElement |
||
67 | */ |
||
68 | 1 | public function createMediaElement(\DomDocument $document, MediaInterface $media) |
|
77 | |||
78 | /** |
||
79 | * @inheritDoc |
||
80 | */ |
||
81 | 2 | protected function hasValue(NodeInterface $node) : bool |
|
85 | |||
86 | /** |
||
87 | * @inheritDoc |
||
88 | */ |
||
89 | 2 | protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
95 | } |
||
96 |
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: