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

MakeScaffoldCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Rougin\Combustor\Commands;
4
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Make Scaffold Command
12
 *
13
 * @package Combustor
14
 * @author  Rougin Royce Gutib <[email protected]>
15
 */
16
class MakeScaffoldCommand extends AbstractCommand
17
{
18
    /**
19
     * Set the configurations of the specified command.
20
     *
21
     * @return void
22
     */
23 6
    protected function configure()
24
    {
25 6
        $this->setName('make:scaffold')->setDescription('Create a new controller class, model class, and view folder');
26 6
        $this->addArgument('table', InputArgument::REQUIRED, 'Name of the table');
27 6
        $this->addOption('type', null, InputArgument::OPTIONAL, 'Type of model: "credo" or "wildfire"', 'wildfire');
28 6
    }
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 3
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39 3
        $commands = [ 'make:controller', 'make:model', 'make:view' ];
40
41 3
        foreach ($commands as $command) {
42 3
            $arguments  = [ 'command' => $command, 'table' => $input->getArgument('table') ];
43
44 3
            if ($command == 'make:model') {
45 3
                $arguments['--type'] = $input->getOption('type');
46 3
            }
47
48 3
            $application = $this->getApplication()->find($command);
49
50 3
            $application->run(new ArrayInput($arguments), $output);
51 3
        }
52 3
    }
53
}
54