1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace LAG\AdminBundle\Twig\Render; |
||||
6 | |||||
7 | use LAG\AdminBundle\Exception\Validation\InvalidActionException; |
||||
8 | use LAG\AdminBundle\Metadata\Link; |
||||
9 | use LAG\AdminBundle\Routing\UrlGenerator\UrlGeneratorInterface; |
||||
10 | use Symfony\Component\Validator\Constraints\Valid; |
||||
11 | use Symfony\Component\Validator\Validator\ValidatorInterface; |
||||
12 | use Twig\Environment; |
||||
13 | |||||
14 | class ActionRenderer implements ActionRendererInterface |
||||
15 | { |
||||
16 | public function __construct( |
||||
17 | private UrlGeneratorInterface $urlGenerator, |
||||
18 | private ValidatorInterface $validator, |
||||
19 | private Environment $environment, |
||||
20 | ) { |
||||
21 | } |
||||
22 | |||||
23 | public function render( |
||||
24 | Link $action, |
||||
25 | mixed $data = null, |
||||
26 | array $options = [] |
||||
27 | ): string { |
||||
28 | $errors = $this->validator->validate($action, [new Valid()]); |
||||
29 | |||||
30 | if ($errors->count() > 0) { |
||||
31 | throw new InvalidActionException($errors); |
||||
32 | } |
||||
33 | |||||
34 | if ($action->getRoute()) { |
||||
35 | $url = $this->urlGenerator->generateFromRouteName( |
||||
36 | $action->getRoute(), |
||||
37 | $action->getRouteParameters(), |
||||
38 | $data, |
||||
39 | ); |
||||
40 | } else { |
||||
41 | $url = $this->urlGenerator->generateFromOperationName( |
||||
42 | $action->getResourceName(), |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
43 | $action->getOperationName(), |
||||
0 ignored issues
–
show
It seems like
$action->getOperationName() can also be of type null ; however, parameter $operationName of LAG\AdminBundle\Routing\...rateFromOperationName() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
44 | $data, |
||||
45 | ); |
||||
46 | } |
||||
47 | |||||
48 | return $this->environment->render($action->getTemplate(), [ |
||||
49 | 'action' => $action, |
||||
50 | 'url' => $url, |
||||
51 | 'options' => $options, |
||||
52 | ]); |
||||
53 | } |
||||
54 | } |
||||
55 |