Passed
Push — master ( 48455b...7b662e )
by Hannes
02:07
created

PipeCompilerPass::processRoute()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 2
nop 1
dl 0
loc 13
rs 10
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\Pipe;
8
use inroutephp\inroute\Compiler\CompilerPassInterface;
9
use inroutephp\inroute\Runtime\RouteInterface;
10
11
final class PipeCompilerPass implements CompilerPassInterface
12
{
13
    public function processRoute(RouteInterface $route): RouteInterface
14
    {
15
        if ($annotation = $route->getAnnotation(Pipe::CLASS)) {
0 ignored issues
show
Bug introduced by
The constant inroutephp\inroute\Annotations\Pipe::CLASS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
            foreach ((array)$annotation->middlewares as $middleware) {
17
                $route = $route->withMiddleware($middleware);
18
            }
19
20
            foreach ((array)$annotation->attributes as $key => $value) {
21
                $route = $route->withAttribute($key, $value);
22
            }
23
        }
24
25
        return $route;
26
    }
27
}
28