Passed
Push — master ( 03e013...bd5966 )
by Anatoly
01:18 queued 14s
created

GenerateOpenApiDocumentationCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 41
c 1
b 0
f 0
ccs 0
cts 23
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 4
A configure() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace App\Command;
4
5
/**
6
 * Import classes
7
 */
8
use App\ContainerAwareTrait;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Import functions
15
 */
16
use function json_encode;
17
18
/**
19
 * Import constants
20
 */
21
use const JSON_PRETTY_PRINT;
22
use const JSON_UNESCAPED_SLASHES;
23
use const JSON_UNESCAPED_UNICODE;
24
25
/**
26
 * GenerateOpenApiDocumentationCommand
27
 */
28
final class GenerateOpenApiDocumentationCommand extends Command
29
{
30
    use ContainerAwareTrait;
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    protected function configure() : void
36
    {
37
        $this->setName('app:openapi:generate-documentation');
38
        $this->setDescription('Generates OpenApi documentation');
39
40
        $this->addOption('pretty', null, null, 'Use whitespace in returned data to format it');
41
        $this->addOption('unescaped-slashes', null, null, 'Do not escape /');
42
        $this->addOption('unescaped-unicode', null, null, 'Encode multi-byte Unicode characters literally');
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output) : int
49
    {
50
        $mode = 0;
51
52
        if ($input->getOption('pretty')) {
53
            $mode |= JSON_PRETTY_PRINT;
54
        }
55
56
        if ($input->getOption('unescaped-slashes')) {
57
            $mode |= JSON_UNESCAPED_SLASHES;
58
        }
59
60
        if ($input->getOption('unescaped-unicode')) {
61
            $mode |= JSON_UNESCAPED_UNICODE;
62
        }
63
64
        $openapi = $this->container->get('openapi');
65
66
        $output->writeln(json_encode($openapi->toArray(), $mode));
67
68
        return 0;
69
    }
70
}
71