DecodeControllerParameters   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 53
ccs 26
cts 26
cp 1
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setParamConverterListener() 0 3 1
A processRequestParameters() 0 8 2
A getParamConverterListener() 0 3 1
A processRequestParametersWithParamConverter() 0 4 2
A getParametersProcessorFactory() 0 3 1
A decodeControllerParameters() 0 9 1
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
Bug introduced by
The call to Pgs\HashIdBundle\Paramet...deParametersProcessor() has too few arguments starting with method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            ->/** @scrutinizer ignore-call */ createControllerDecodeParametersProcessor(...$controller);

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.

Loading history...
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