EncodeParametersProcessorFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createRouteEncodeParametersProcessor() 0 13 3
A getEncodeParametersProcessor() 0 3 1
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pgs\HashIdBundle\ParametersProcessor\Factory;
6
7
use Pgs\HashIdBundle\Annotation\Hash;
8
use Pgs\HashIdBundle\AnnotationProvider\AnnotationProvider;
9
use Pgs\HashIdBundle\Exception\InvalidControllerException;
10
use Pgs\HashIdBundle\Exception\MissingClassOrMethodException;
11
use Pgs\HashIdBundle\ParametersProcessor\ParametersProcessorInterface;
12
use Symfony\Component\Routing\Route;
13
14
class EncodeParametersProcessorFactory extends AbstractParametersProcessorFactory
15
{
16
    /**
17
     * @var ParametersProcessorInterface
18
     */
19
    protected $encodeParametersProcessor;
20
21 3
    public function __construct(
22
        AnnotationProvider $annotationProvider,
23
        ParametersProcessorInterface $noOpParametersProcessor,
24
        ParametersProcessorInterface $encodeParametersProcessor
25
    ) {
26 3
        parent::__construct($annotationProvider, $noOpParametersProcessor);
27 3
        $this->encodeParametersProcessor = $encodeParametersProcessor;
28 3
    }
29
30 3
    public function createRouteEncodeParametersProcessor(Route $route)
31
    {
32 3
        $controller = $route->getDefault('_controller');
33
        try {
34
            /** @var Hash $annotation */
35 3
            $annotation = $this->getAnnotationProvider()->getFromString($controller, Hash::class);
36 1
        } catch (InvalidControllerException | MissingClassOrMethodException $e) {
37 1
            $annotation = null;
38
        }
39
40 3
        return null !== $annotation
41 2
            ? $this->getEncodeParametersProcessor()->setParametersToProcess($annotation->getParameters())
42 3
            : $this->getNoOpParametersProcessor();
43
    }
44
45 2
    protected function getEncodeParametersProcessor(): ParametersProcessorInterface
46
    {
47 2
        return $this->encodeParametersProcessor;
48
    }
49
}
50