Completed
Pull Request — master (#17)
by Rougin
11:45
created

MakeControllerCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Rougin\Combustor\Commands;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
use Rougin\Combustor\Common\DataGenerator;
10
11
/**
12
 * Make Controller Command
13
 *
14
 * @package Combustor
15
 * @author  Rougin Royce Gutib <[email protected]>
16
 */
17
class MakeControllerCommand extends AbstractCommand
18
{
19
    /**
20
     * Set the configurations of the specified command.
21
     *
22
     * @return void
23
     */
24 9
    protected function configure()
25
    {
26 9
        $this->setName('make:controller')->setDescription('Create a new controller class');
27 9
        $this->addArgument('table', InputArgument::REQUIRED, 'Name of the table');
28 9
    }
29
30
    /**
31
     * Executes the current command.
32
     *
33
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
34
     * @param  \Symfony\Component\Console\Input\OutputInterface $output
35
     * @return void
36
     */
37 6
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39 6
        $contents = (new DataGenerator($this->describe, $input))->generate();
40 6
        $filename = ucfirst(plural(underscore($input->getArgument('table'))));
41 6
        $rendered = $this->renderer->render('Controller.twig', $contents);
42
43 6
        $this->filesystem->write('application/controllers/' . $filename . '.php', $rendered);
44
45 6
        $output->writeln('<info>Controller created successfully!</info>');
46 6
    }
47
}
48