1 | <?php |
||
12 | final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var \Twig_Environment |
||
16 | */ |
||
17 | private $twig; |
||
18 | |||
19 | /** |
||
20 | * @var OptionsParserInterface |
||
21 | */ |
||
22 | private $optionsParser; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $bulkActionTemplates; |
||
28 | |||
29 | /** |
||
30 | * @param \Twig_Environment $twig |
||
31 | * @param OptionsParserInterface $optionsParser |
||
32 | * @param array $bulkActionTemplates |
||
33 | */ |
||
34 | public function __construct( |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function renderBulkAction(GridViewInterface $gridView, Action $bulkAction, $data = null): string |
||
67 | } |
||
68 |
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: