Completed
Push — 8.x-1.x ( 0421f5...0df7dc )
by
unknown
25:14
created

Route::allowArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Drupal\controller_annotations\Configuration;
4
5
use Symfony\Component\Routing\Annotation\Route as BaseRoute;
6
use Symfony\Component\Routing\Route as RoutingRoute;
7
8
/**
9
 * @Annotation
10
 */
11
class Route extends BaseRoute implements RouteModifierMethodInterface, RouteModifierClassInterface
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $service;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $admin;
23
24
    /**
25
     * @param $service
26
     */
27 7
    public function setService($service)
28
    {
29
        // avoid a BC notice in case of @Route(service="") with sf ^2.7
30 7
        if (null === $this->getPath()) {
31 7
            $this->setPath('');
32
        }
33 7
        $this->service = $service;
34 7
    }
35
36 8
    public function getService()
37
    {
38 8
        return $this->service;
39
    }
40
41
    /**
42
     * @return bool
43
     */
44 8
    public function isAdmin()
45
    {
46 8
        return $this->admin;
47
    }
48
49
    /**
50
     * @param bool $admin
51
     * @return Route
52
     */
53 7
    public function setAdmin($admin)
54
    {
55 7
        $this->admin = $admin;
56
57 7
        return $this;
58
    }
59
60
    /**
61
     * Multiple route annotations are allowed.
62
     *
63
     * @return bool
64
     *
65
     * @see ConfigurationInterface
66
     */
67 1
    public function allowArray()
68
    {
69 1
        return true;
70
    }
71
72
    /**
73
     * @param RoutingRoute $route
74
     * @param \ReflectionClass $class
75
     * @param \ReflectionMethod $method
76
     */
77 7
    public function modifyRouteClass(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method)
78
    {
79 7
        $this->modifyRoute($route, $class, $method);
80 7
    }
81
82
    /**
83
     * @param RoutingRoute $route
84
     * @param \ReflectionClass $class
85
     * @param \ReflectionMethod $method
86
     */
87 8
    public function modifyRouteMethod(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method)
88
    {
89 8
        if ($this->getService()) {
90 1
            throw new \LogicException('The service option can only be specified at class level.');
91
        }
92
93 7
        $this->modifyRoute($route, $class, $method);
94 7
    }
95
96
    /**
97
     * @param RoutingRoute $route
98
     * @param \ReflectionClass $class
99
     * @param \ReflectionMethod $method
100
     */
101 8
    protected function modifyRoute(RoutingRoute $route, \ReflectionClass $class, \ReflectionMethod $method)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $method is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
    {
103 8
        if ($this->isAdmin()) {
104 7
            $route->setOption('_admin_route', true);
105
        }
106 8
    }
107
}
108