Passed
Pull Request — master (#10)
by Anatoly
02:28
created

GenerateOpenApiDocumentCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 6
rs 10
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
 * GenerateOpenApiDocumentCommand
27
 */
28
final class GenerateOpenApiDocumentCommand extends Command
29
{
30
    use ContainerAwareTrait;
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    protected function configure() : void
36
    {
37
        $this->setName('app:openapi:generate-document');
38
        $this->setDescription('Generates OpenApi document');
39
40
        $this->addOption('pretty');
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output) : int
47
    {
48
        $mode = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
49
50
        if ($input->getOption('pretty')) {
51
            $mode |= JSON_PRETTY_PRINT;
52
        }
53
54
        $output->writeln(json_encode($this->container->get('openapi')->toArray(), $mode));
55
56
        return 0;
57
    }
58
}
59