OpenApiCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A processRoute() 0 20 4
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
        /** @var ?Operation $operation */
17
        $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...
18
19
        if ($operation) {
20
            $route = $route
21
                ->withRoutable(true)
22
                ->withHttpMethod($operation->method);
23
24
            if ($operation->path != UNDEFINED) {
25
                $route = $route->withPath($operation->path);
26
            }
27
28
            if ($operation->operationId != UNDEFINED) {
29
                $route = $route->withName($operation->operationId);
30
            }
31
        }
32
33
        return $route;
34
    }
35
}
36