1 | <?php |
||
7 | class DisplayImage extends AbstractHtmlElement |
||
8 | { |
||
9 | /** |
||
10 | * Attributes for HTML image tag |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $attributes; |
||
15 | |||
16 | /** |
||
17 | * Gets valid HTML image tag or self when $relativeName is not provided |
||
18 | * |
||
19 | * @param string $relativeName Relative Path |
||
20 | * @param string $filter Filter Service |
||
21 | * @param array $attributes Attributes for HTML image tag |
||
22 | * @return string |
||
23 | */ |
||
24 | 1 | public function __invoke($relativeName = null, $filter = null, $attributes = null) |
|
35 | |||
36 | /** |
||
37 | * Return valid HTML image tag |
||
38 | * |
||
39 | * @param string $relativeName |
||
40 | * @param string $filter |
||
41 | * @return string |
||
42 | */ |
||
43 | 1 | public function getImgTag($relativeName, $filter) |
|
53 | |||
54 | /** |
||
55 | * Sets attributes of HTML image tag |
||
56 | * |
||
57 | * @param array $attributes |
||
58 | * @return self |
||
59 | */ |
||
60 | 2 | public function setAttributes(array $attributes) |
|
66 | |||
67 | /** |
||
68 | * Gets attributes of img tag |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | 2 | public function getAttributes() |
|
76 | |||
77 | } |
||
78 |
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: