Completed
Push — master ( d2fb93...a24186 )
by Narcotic
26:10 queued 11:13
created

SwaggerGenerateCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * Generates swagger.json
4
 */
5
6
namespace Graviton\SwaggerBundle\Command;
7
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * Generates swagger.json
15
 *
16
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
18
 * @link     http://swisscom.ch
19
 */
20
class SwaggerGenerateCommand extends Command
21
{
22
23
    /**
24
     * container
25
     *
26
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
27
     */
28
    private $container;
29
30
    /**
31
     * root dir
32
     *
33
     * @var string
34
     */
35
    private $rootDir;
36
37
    /**
38
     * filesystem
39
     *
40
     * @var \Symfony\Component\Filesystem\Filesystem
41
     */
42
    private $filesystem;
43
44
    /**
45
     * apidoc service
46
     *
47
     * @var \Graviton\SwaggerBundle\Service\Swagger
48
     */
49
    private $apidoc;
50
51
    /**
52
     * {@inheritDoc}
53
     *
54
     * @return void
55
     */
56 4
    protected function configure()
57
    {
58 4
        parent::configure();
59
60 4
        $this->setName('graviton:swagger:generate')
61 4
             ->setDescription(
62 4
                 'Generates swagger.json in web dir'
63
             );
64 4
    }
65
66
    /**
67
     * set container
68
     *
69
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container service_container
70
     *
71
     * @return void
72
     */
73 4
    public function setContainer($container)
74
    {
75 4
        $this->container = $container;
76 4
    }
77
78
    /**
79
     * sets the root dir
80
     *
81
     * @param string $rootDir root dir
82
     *
83
     * @return void
84
     */
85 4
    public function setRootDir($rootDir)
86
    {
87 4
        $this->rootDir = $rootDir;
88 4
    }
89
90
    /**
91
     * set filesystem
92
     *
93
     * @param mixed $filesystem filesystem
94
     *
95
     * @return void
96
     */
97 4
    public function setFilesystem($filesystem)
98
    {
99 4
        $this->filesystem = $filesystem;
100 4
    }
101
102
    /**
103
     * sets apidoc
104
     *
105
     * @param mixed $apidoc apidoc
106
     *
107
     * @return void
108
     */
109 4
    public function setApidoc($apidoc)
110
    {
111 4
        $this->apidoc = $apidoc;
112 4
    }
113
114
    /**
115
     * {@inheritDoc}
116
     *
117
     * @param InputInterface  $input  input
118
     * @param OutputInterface $output output
119
     *
120
     * @return void
121
     */
122
    protected function execute(InputInterface $input, OutputInterface $output)
123
    {
124
        $this->filesystem->dumpFile(
125
            $this->rootDir.'/../app/cache/swagger.json',
126
            json_encode($this->apidoc->getSwaggerSpec())
127
        );
128
    }
129
}
130