RouteReader::getRoutes()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
rs 9.8333
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Reader;
6
7
use Neimheadh\SonataAnnotationBundle\Annotation\AddRoute;
8
use Neimheadh\SonataAnnotationBundle\Annotation\RemoveRoute;
9
use Neimheadh\SonataAnnotationBundle\Annotation\RouteAnnotationInterface;
10
use ReflectionClass;
11
12
/**
13
 * Route configuration reader.
14
 *
15
 * @author Marko Kunic <[email protected]>
16
 * @author Mathieu Wambre <[email protected]>
17
 */
18
final class RouteReader extends AbstractReader
19
{
20
21
    /**
22
     * Get admin routes.
23
     *
24
     * @param ReflectionClass $class Entity class.
25
     *
26
     * @return array<array<string, object>> Route name => route annotations,
27
     *                             added route key 0, removed routes key 1.
28
     */
29
    public function getRoutes(ReflectionClass $class): array
30
    {
31
        $addRoutes = [];
32
        $removeRoutes = [];
33
34
        foreach (
35
            $this->getClassAnnotations(
36
                $class,
37
                RouteAnnotationInterface::class
38
            ) as $annotation
39
        ) {
40
            if ($annotation instanceof AddRoute) {
41
                $addRoutes[$annotation->name] = $annotation;
42
                continue;
43
            }
44
45
            if ($annotation instanceof RemoveRoute) {
46
                $removeRoutes[$annotation->name] = $annotation;
47
            }
48
        }
49
50
        return [$addRoutes, $removeRoutes];
51
    }
52
53
}
54