RoutingAnnotationLoader::configureRoute()   B
last analyzed

Complexity

Conditions 6
Paths 18

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6.0106

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 14
cts 15
cp 0.9333
rs 8.8817
c 0
b 0
f 0
cc 6
nc 18
nop 4
crap 6.0106
1
<?php
2
declare(strict_types=1);
3
4
namespace Paysera\Bundle\ApiBundle\Service\Annotation;
5
6
use Paysera\Bundle\ApiBundle\Annotation\RestAnnotationInterface;
7
use Paysera\Bundle\ApiBundle\Service\RestRequestHelper;
8
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
9
use Symfony\Component\Routing\Route;
10
use ReflectionClass;
11
use ReflectionMethod;
12
13
/**
14
 * @internal
15
 */
16
class RoutingAnnotationLoader extends AnnotatedRouteControllerLoader
17
{
18
    /**
19
     * @var RestRequestHelper
20
     */
21
    private $restRequestHelper;
22
23
    /**
24
     * @var RestRequestOptionsBuilder
25
     */
26
    private $restRequestOptionsBuilder;
27
28 96
    public function setRequestHelper(RestRequestHelper $restRequestHelper)
29
    {
30 96
        $this->restRequestHelper = $restRequestHelper;
31 96
    }
32
33 96
    public function setRestRequestOptionsBuilder(RestRequestOptionsBuilder $restRequestOptionsBuilder)
34
    {
35 96
        $this->restRequestOptionsBuilder = $restRequestOptionsBuilder;
36 96
    }
37
38 96
    protected function configureRoute(Route $route, ReflectionClass $class, ReflectionMethod $method, $routeAnnotation)
39
    {
40 96
        parent::configureRoute($route, $class, $method, $routeAnnotation);
41
42 96
        $annotations = [];
43 96
        foreach ($this->reader->getClassAnnotations($class) as $annotation) {
44 96
            if ($annotation instanceof RestAnnotationInterface) {
45 96
                $annotations[] = $annotation;
46
            }
47
        }
48
49 96
        foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
50 96
            if ($annotation instanceof RestAnnotationInterface) {
51 96
                $annotations[] = $annotation;
52
            }
53
        }
54
55 96
        if (count($annotations) === 0) {
56
            return;
57
        }
58
59 96
        $this->restRequestHelper->setOptionsForRoute(
60 96
            $route,
61 96
            $this->restRequestOptionsBuilder->buildOptions($annotations, $method)
62
        );
63 96
    }
64
}
65