Completed
Pull Request — master (#591)
by Amrouche
06:27
created

SwaggerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 7 1
A execute() 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\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
22
/**
23
 * Console command to dump Swagger API documentations.
24
 *
25
 * @author Amrouche Hamza <[email protected]>
26
 */
27
class SwaggerCommand extends Command
28
{
29
    /**
30
     * @var ApiDocumentationBuilder
31
     */
32
    protected $apiDocumentationBuilder;
33
34
    public function __construct(ApiDocumentationBuilder $apiDocumentationBuilder)
35
    {
36
        $this->apiDocumentationBuilder = $apiDocumentationBuilder;
37
38
        parent::__construct();
39
    }
40
41
    protected function configure()
42
    {
43
44
        $this
45
            ->setName('api:swagger:export')
46
            ->setDescription('Export a beautiful json of swagger api');
47
    }
48
49
    protected function execute(InputInterface $input, OutputInterface $output)
50
    {
51
        $data = $this->apiDocumentationBuilder->getApiDocumentation();
52
        $content = json_encode($data, JSON_PRETTY_PRINT);
53
        $output->writeln($content);
54
    }
55
}