Passed
Push — master ( 26f9dc...b66765 )
by Marko
02:57
created

RouteReader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 31
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoutes() 0 17 4
A isAddRoute() 0 3 1
A isRemoveRoute() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\Reader;
6
7
use KunicMarko\SonataAnnotationBundle\Annotation\AddRoute;
8
use KunicMarko\SonataAnnotationBundle\Annotation\RemoveRoute;
9
10
/**
11
 * @author Marko Kunic <[email protected]>
12
 */
13
class RouteReader
14
{
15
    use AnnotationReaderTrait;
16
17
    public function getRoutes(\ReflectionClass $class): array
18
    {
19
        $addRoutes = [];
20
        $removeRoutes = [];
21
22
        foreach ($this->getClassAnnotations($class) as $annotation) {
23
            if ($this->isAddRoute($annotation)) {
24
                $addRoutes[$annotation->name] = $annotation;
25
                continue;
26
            }
27
28
            if ($this->isRemoveRoute($annotation)) {
29
                $removeRoutes[$annotation->name] = $annotation;
30
            }
31
        }
32
33
        return [$addRoutes, $removeRoutes];
34
    }
35
36
    private function isAddRoute($annotation): bool
37
    {
38
        return $annotation instanceof AddRoute;
39
    }
40
41
    private function isRemoveRoute($annotation): bool
42
    {
43
        return $annotation instanceof RemoveRoute;
44
    }
45
}
46