CreateScaffoldCommand::execute()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 42
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 28
c 2
b 0
f 0
nc 9
nop 2
dl 0
loc 42
ccs 28
cts 28
cp 1
crap 6
rs 8.8497
1
<?php
2
3
namespace Rougin\Combustor\Commands;
4
5
use Rougin\Combustor\Common\Tools;
6
use Symfony\Component\Console\Input\ArrayInput;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Create Scaffold Command
14
 *
15
 * Generates a Wildfire or Doctrine-based controller,
16
 * model and view files for CodeIgniter
17
 *
18
 * @package Combustor
19
 * @author  Rougin Gutib <[email protected]>
20
 */
21
class CreateScaffoldCommand extends AbstractCommand
22
{
23
    /**
24
     * Checks whether the command is enabled or not in the current environment.
25
     *
26
     * @return bool
27
     */
28 6
    public function isEnabled()
29
    {
30 6
        return Tools::isCommandEnabled();
31
    }
32
33
    /**
34
     * Sets the configurations of the specified command.
35
     *
36
     * @return void
37
     */
38 6
    protected function configure()
39
    {
40 6
        $this->setName('create:scaffold')
41 6
            ->setDescription('Creates a new controller, model and view')
42 6
            ->addArgument(
43 6
                'name',
44 6
                InputArgument::REQUIRED,
45 2
                'Name of the table'
46 6
            )->addOption(
47 6
                'bootstrap',
48 6
                null,
49 6
                InputOption::VALUE_NONE,
50 2
                'Includes the Bootstrap CSS/JS Framework tags'
51 6
            )->addOption(
52 6
                'camel',
53 6
                null,
54 6
                InputOption::VALUE_NONE,
55 2
                'Uses the camel case naming convention'
56 6
            )->addOption(
57 6
                'keep',
58 6
                null,
59 6
                InputOption::VALUE_NONE,
60 2
                'Keeps the name to be used'
61 6
            )->addOption(
62 6
                'lowercase',
63 6
                null,
64 6
                InputOption::VALUE_NONE,
65 2
                'Keeps the first character of the name to lowercase'
66 4
            );
67 6
    }
68
69
    /**
70
     * Executes the command.
71
     *
72
     * @param \Symfony\Component\Console\Input\InputInterface   $input
73
     * @param \Symfony\Component\Console\Output\OutputInterface $output
74
     * @return object|\Symfony\Component\Console\Output\OutputInterface
75
     */
76 3
    protected function execute(InputInterface $input, OutputInterface $output)
77
    {
78
        $commands = [
79 3
            'create:controller',
80 2
            'create:model',
81
            'create:view'
82 2
        ];
83
84 3
        $bootstrap = $input->getOption('bootstrap');
85 3
        $camel = $input->getOption('camel');
86 3
        $keep = $input->getOption('keep');
87 3
        $lowercase = $input->getOption('lowercase');
88
89 3
        foreach ($commands as $command) {
90
            $arguments = [
91 3
                'command' => $command,
92 3
                'name' => $input->getArgument('name')
93 2
            ];
94
95
            switch ($command) {
96 3
                case 'create:controller':
97 3
                case 'create:model':
98 3
                    $arguments['--camel'] = $camel;
99 3
                    $arguments['--lowercase'] = $lowercase;
100
101 3
                    break;
102 3
                case 'create:view':
103 3
                    $arguments['--bootstrap'] = $bootstrap;
104 3
                    $arguments['--camel'] = $camel;
105 3
                    $arguments['--keep'] = $keep;
106
107 3
                    break;
108
            }
109
110 3
            if ($command == 'create:controller') {
111 3
                $arguments['--keep'] = $keep;
112 2
            }
113
114 3
            $input = new ArrayInput($arguments);
115
116 3
            $application = $this->getApplication()->find($command);
117 3
            $application->run($input, $output);
118 2
        }
119 3
    }
120
}
121