Completed
Push — 8.x-1.x ( 5411ec...980b0f )
by
unknown
33:53 queued 31:38
created

AnnotatedRouteControllerLoader::setSecurityConfiguration()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 14
cts 14
cp 1
rs 7.551
cc 7
eloc 13
nc 64
nop 2
crap 7
1
<?php
2
3
namespace Drupal\controller_annotations\Routing;
4
5
use Drupal\controller_annotations\Configuration\RouteModifierInterface;
6
use Drupal\controller_annotations\Configuration\Route as RouteConfiguration;
7
use Sensio\Bundle\FrameworkExtraBundle\Routing\AnnotatedRouteControllerLoader as BaseAnnotatedRouteControllerLoader;
8
use Symfony\Component\Routing\Route;
9
10
class AnnotatedRouteControllerLoader extends BaseAnnotatedRouteControllerLoader
11
{
12
    /**
13
     * @param Route $route
14
     * @param \ReflectionClass $class
15
     * @param \ReflectionMethod $method
16
     * @param mixed $annotation
17
     */
18 6
    protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annotation)
19
    {
20 6
        $this->setController($route, $class, $method);
21
22 6
        foreach ($this->reader->getMethodAnnotations($method) as $configuration) {
23 6
            if ($configuration instanceof RouteModifierInterface) {
24 6
                $configuration->modifyRoute($route);
25
            }
26
27 6
            if ($configuration instanceof RouteConfiguration && $configuration->getService()) {
28 6
                throw new \LogicException('The service option can only be specified at class level.');
29
            }
30
        }
31 6
    }
32
33
    /**
34
     * @param Route $route
35
     * @param \ReflectionClass $class
36
     * @param \ReflectionMethod $method
37
     */
38 6
    private function setController(Route $route, \ReflectionClass $class, \ReflectionMethod $method)
39
    {
40 6
        $classAnnotation = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass);
41 6
        if ($classAnnotation instanceof RouteConfiguration && $service = $classAnnotation->getService()) {
42 5
            $route->setDefault('_controller', $service . ':' . $method->getName());
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
43
        } else {
44 6
            $route->setDefault('_controller', $class->getName() . '::' . $method->getName());
0 ignored issues
show
Bug introduced by
Consider using $class->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
45
        }
46 6
    }
47
}
48