Completed
Pull Request — master (#591)
by Amrouche
03:11
created

SwaggerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 1
cbo 3
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 6 1
A __construct() 0 5 1
A configure() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Command;
13
14
use ApiPlatform\Core\Swagger\ApiDocumentationBuilder;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Console command to dump Swagger API documentations.
21
 *
22
 * @author Amrouche Hamza <[email protected]>
23
 */
24
final class SwaggerCommand extends Command
25
{
26
    private $apiDocumentationBuilder;
27
28
    public function __construct(ApiDocumentationBuilder $apiDocumentationBuilder)
29
    {
30
        parent::__construct();
31
        $this->apiDocumentationBuilder = $apiDocumentationBuilder;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function configure()
38
    {
39
        $this
40
            ->setName('api:swagger:export')
41
            ->setDescription('Dump the Swagger 2.0 (OpenAPI) documentation');
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $data = $this->apiDocumentationBuilder->getApiDocumentation();
50
        $content = json_encode($data, JSON_PRETTY_PRINT);
51
        $output->writeln($content);
52
    }
53
}
54