Completed
Push — master ( 83b89e...48455b )
by Hannes
04:08 queued 02:15
created

RouteCompilerPass::processRoute()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 1
dl 0
loc 20
rs 9.6111
c 0
b 0
f 0
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
        if ($annotation = $route->getAnnotation(Route::CLASS)) {
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...
16
            $route = $route
17
                ->withRoutable(true)
18
                ->withHttpMethod($annotation->method)
19
                ->withPath($annotation->path);
20
21
            if ($annotation->name) {
22
                $route = $route->withName($annotation->name);
23
            }
24
25
            if ($annotation->attributes) {
26
                foreach ((array)$annotation->attributes as $key => $value) {
27
                    $route = $route->withAttribute($key, $value);
28
                }
29
            }
30
        }
31
32
        return $route;
33
    }
34
}
35