1 | <?php |
||
24 | final class TwigGridRenderer implements GridRendererInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var GridRendererInterface |
||
28 | */ |
||
29 | private $gridRenderer; |
||
30 | |||
31 | /** |
||
32 | * @var \Twig_Environment |
||
33 | */ |
||
34 | private $twig; |
||
35 | |||
36 | /** |
||
37 | * @var OptionsParserInterface |
||
38 | */ |
||
39 | private $optionsParser; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | private $actionTemplates; |
||
45 | |||
46 | /** |
||
47 | * @param GridRendererInterface $gridRenderer |
||
48 | * @param \Twig_Environment $twig |
||
49 | * @param OptionsParserInterface $optionsParser |
||
50 | * @param array $actionTemplates |
||
51 | */ |
||
52 | public function __construct( |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function render(GridViewInterface $gridView, $template = null) |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function renderField(GridViewInterface $gridView, Field $field, $data) |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function renderAction(GridViewInterface $gridView, Action $action, $data = null) |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function renderFilter(GridViewInterface $gridView, Filter $filter) |
||
111 | } |
||
112 |
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: