1 | <?php |
||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Bundle\ResourceBundle\Grid\Renderer; |
||
15 | |||
16 | use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface; |
||
17 | use Sylius\Component\Grid\Definition\Action; |
||
18 | use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface; |
||
19 | use Sylius\Component\Grid\View\GridViewInterface; |
||
20 | |||
21 | final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var \Twig_Environment |
||
25 | */ |
||
26 | private $twig; |
||
27 | |||
28 | /** |
||
29 | * @var OptionsParserInterface |
||
30 | */ |
||
31 | private $optionsParser; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
43 | public function __construct( |
||
44 | \Twig_Environment $twig, |
||
45 | OptionsParserInterface $optionsParser, |
||
46 | array $bulkActionTemplates = [] |
||
47 | ) { |
||
67 | ); |
||
68 | |||
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 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: