RouterOpenApiBuildDocumentCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 16 1
A __construct() 0 5 1
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\OpenApi\Command;
15
16
use Sunrise\Http\Router\OpenApi\OpenApiDocumentManagerInterface;
17
use Sunrise\Http\Router\RouteInterface;
18
use Sunrise\Http\Router\RouterInterface;
19
use Symfony\Component\Console\Attribute\AsCommand;
20
use Symfony\Component\Console\Command\Command;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
24
use function array_filter;
25
26
/**
27
 * @since 3.0.0
28
 */
29
#[AsCommand('router:openapi:build-document', 'Builds the OpenAPI document.')]
30
final class RouterOpenApiBuildDocumentCommand extends Command
31
{
32 3
    public function __construct(
33
        private readonly RouterInterface $router,
34
        private readonly OpenApiDocumentManagerInterface $openApiDocumentManager,
35
    ) {
36 3
        parent::__construct();
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 3
    protected function execute(InputInterface $input, OutputInterface $output): int
43
    {
44 3
        $this->openApiDocumentManager->saveDocument(
45 3
            $this->openApiDocumentManager->buildDocument(
46 3
                array_filter(
47 3
                    $this->router->getRoutes(),
48 3
                    static function (RouteInterface $route): bool {
49 3
                        return $route->isApiRoute();
50 3
                    },
51 3
                )
52 3
            )
53 3
        );
54
55 1
        $output->writeln('Done.');
56
57 1
        return self::SUCCESS;
58
    }
59
}
60