1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Pgs\HashIdBundle\Service; |
||
6 | |||
7 | use Pgs\HashIdBundle\ParametersProcessor\Factory\DecodeParametersProcessorFactory; |
||
8 | use Pgs\HashIdBundle\ParametersProcessor\ParametersProcessorInterface; |
||
9 | use Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener; |
||
10 | use Symfony\Component\HttpKernel\Event\ControllerEvent; |
||
11 | |||
12 | class DecodeControllerParameters |
||
13 | { |
||
14 | protected $parametersProcessorFactory; |
||
15 | |||
16 | protected $paramConverterListener; |
||
17 | |||
18 | 2 | public function __construct(DecodeParametersProcessorFactory $parametersProcessorFactory) |
|
19 | { |
||
20 | 2 | $this->parametersProcessorFactory = $parametersProcessorFactory; |
|
21 | 2 | } |
|
22 | |||
23 | 2 | public function decodeControllerParameters(ControllerEvent $event): void |
|
24 | { |
||
25 | 2 | $controller = $event->getController(); |
|
26 | $parametersProcessor = $this |
||
0 ignored issues
–
show
|
|||
27 | 2 | ->getParametersProcessorFactory() |
|
28 | 2 | ->createControllerDecodeParametersProcessor(...$controller); |
|
29 | |||
30 | 2 | $this->processRequestParameters($event, $parametersProcessor); |
|
31 | 2 | $this->processRequestParametersWithParamConverter($event); |
|
32 | 2 | } |
|
33 | |||
34 | 2 | protected function processRequestParameters( |
|
35 | ControllerEvent $event, |
||
36 | ParametersProcessorInterface $parametersProcessor |
||
37 | ): void { |
||
38 | 2 | if ($parametersProcessor->needToProcess()) { |
|
39 | 2 | $requestParams = $event->getRequest()->attributes->all(); |
|
40 | 2 | $processedParams = $parametersProcessor->process($requestParams); |
|
41 | 2 | $event->getRequest()->attributes->replace($processedParams); |
|
42 | } |
||
43 | 2 | } |
|
44 | |||
45 | 2 | protected function processRequestParametersWithParamConverter(ControllerEvent $event): void |
|
46 | { |
||
47 | 2 | if (null !== $this->getParamConverterListener()) { |
|
48 | 1 | $this->getParamConverterListener()->onKernelController($event); |
|
49 | } |
||
50 | 2 | } |
|
51 | |||
52 | 2 | public function getParametersProcessorFactory(): DecodeParametersProcessorFactory |
|
53 | { |
||
54 | 2 | return $this->parametersProcessorFactory; |
|
55 | } |
||
56 | |||
57 | 2 | public function getParamConverterListener(): ?ParamConverterListener |
|
58 | { |
||
59 | 2 | return $this->paramConverterListener; |
|
60 | } |
||
61 | |||
62 | 1 | public function setParamConverterListener(ParamConverterListener $paramConverterListener): void |
|
63 | { |
||
64 | 1 | $this->paramConverterListener = $paramConverterListener; |
|
65 | 1 | } |
|
66 | } |
||
67 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.