1 | <?php |
||
17 | class ImageRenderer implements InlineRendererInterface |
||
18 | { |
||
19 | /** |
||
20 | * Url Translation |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $urlTranslation; |
||
25 | |||
26 | /** |
||
27 | * Constructor |
||
28 | * |
||
29 | * @param array $urlTranslation |
||
30 | */ |
||
31 | public function __construct(array $urlTranslation) |
||
35 | |||
36 | /** |
||
37 | * Get url translation |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | public function getUrlTranslation() : array |
||
45 | |||
46 | /** |
||
47 | * Render image |
||
48 | * |
||
49 | * {@inheritDoc} |
||
50 | * @see \League\CommonMark\Inline\Renderer\InlineRendererInterface::render() |
||
51 | */ |
||
52 | public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) |
||
77 | } |
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 sub-classes 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 parent class: