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

OpenApiCompilerPass::processRoute()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 5
nop 1
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace inroutephp\inroute\Compiler\OpenApi;
6
7
use inroutephp\inroute\Compiler\CompilerPassInterface;
8
use inroutephp\inroute\Runtime\RouteInterface;
9
use OpenApi\Annotations\Operation;
10
use const OpenApi\Annotations\UNDEFINED;
11
12
final class OpenApiCompilerPass implements CompilerPassInterface
13
{
14
    public function processRoute(RouteInterface $route): RouteInterface
15
    {
16
        if ($operation = $route->getAnnotation(Operation::CLASS)) {
0 ignored issues
show
Bug introduced by
The constant OpenApi\Annotations\Operation::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($operation->method);
20
21
            if ($operation->path != UNDEFINED) {
22
                $route = $route->withPath($operation->path);
23
            }
24
25
            if ($operation->operationId != UNDEFINED) {
26
                $route = $route->withName($operation->operationId);
27
            }
28
        }
29
30
        return $route;
31
    }
32
}
33