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

MakeScaffoldCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 38
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 16 3
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