Completed
Push — dev-master ( 91304f...d78e93 )
by Karol
02:48
created

DecodeControllerParameters::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\FilterControllerEvent;
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(FilterControllerEvent $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
        FilterControllerEvent $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(FilterControllerEvent $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