RouteCompilerPass::processRoute()   A
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 22
rs 9.6111
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace inroutephp\inroute\Compiler\Dsl;
6
7
use inroutephp\inroute\Annotations\Route;
8
use inroutephp\inroute\Compiler\CompilerPassInterface;
9
use inroutephp\inroute\Runtime\RouteInterface;
10
11
final class RouteCompilerPass implements CompilerPassInterface
12
{
13
    public function processRoute(RouteInterface $route): RouteInterface
14
    {
15
        /** @var Route $annotation */
16
        foreach ($route->getAnnotations(Route::CLASS) as $annotation) {
0 ignored issues
show
Bug introduced by
The constant inroutephp\inroute\Annotations\Route::CLASS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
17
            $route = $route
18
                ->withRoutable(true)
19
                ->withHttpMethod($annotation->method);
20
21
            if ($annotation->path) {
22
                $route = $route->withPath($annotation->path);
23
            }
24
25
            if ($annotation->name) {
26
                $route = $route->withName($annotation->name);
27
            }
28
29
            foreach ((array)$annotation->attributes as $key => $value) {
30
                $route = $route->withAttribute($key, $value);
31
            }
32
        }
33
34
        return $route;
35
    }
36
}
37