Completed
Push — master ( da9ea2...cfe8fe )
by Rougin
08:08
created

CreateScaffoldCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 32
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 40
ccs 32
cts 32
cp 1
rs 8.8571
c 2
b 1
f 0
cc 1
eloc 37
nc 1
nop 0
crap 1
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 Royce 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
     * Override this to check for x or y and return false if the command can not
27
     * run properly under the current conditions.
28
     *
29
     * @return bool
30
     */
31 3
    public function isEnabled()
32
    {
33 3
        return Tools::isCommandEnabled();
34
    }
35
36
    /**
37
     * Sets the configurations of the specified command.
38
     *
39
     * @return void
40
     */
41 3
    protected function configure()
42
    {
43 3
        $this->setName('create:scaffold')
44 3
            ->setDescription('Createss a new controller, model and view')
45 3
            ->addArgument(
46 3
                'name',
47 3
                InputArgument::REQUIRED,
48
                'Name of the controller, model and view'
49 3
            )->addOption(
50 3
                'bootstrap',
51 3
                NULL,
52 3
                InputOption::VALUE_NONE,
53
                'Includes the Bootstrap CSS/JS Framework tags'
54 3
            )->addOption(
55 3
                'camel',
56 3
                NULL,
57 3
                InputOption::VALUE_NONE,
58
                'Uses the camel case naming convention'
59 3
            )->addOption(
60 3
                'doctrine',
61 3
                NULL,
62 3
                InputOption::VALUE_NONE,
63
                'Uses the Doctrine\'s specifications'
64 3
            )->addOption(
65 3
                'keep',
66 3
                null,
67 3
                InputOption::VALUE_NONE,
68
                'Keeps the name to be used'
69 3
            )->addOption(
70 3
                'lowercase',
71 3
                null,
72 3
                InputOption::VALUE_NONE,
73
                'Keeps the first character of the name to lowercase'
74 3
            )->addOption(
75 3
                'wildfire',
76 3
                NULL,
77 3
                InputOption::VALUE_NONE,
78
                'Uses the Wildfire\'s specifications'
79 3
            );
80 3
    }
81
82
    /**
83
     * Executes the command.
84
     * 
85
     * @param \Symfony\Component\Console\Input\InputInterface   $input
86
     * @param \Symfony\Component\Console\Output\OutputInterface $output
87
     * @return object|\Symfony\Component\Console\Output\OutputInterface
88
     */
89
    protected function execute(InputInterface $input, OutputInterface $output)
90
    {
91
        $commands = [
92
            'create:controller',
93
            'create:model',
94
            'create:view'
95
        ];
96
97
        foreach ($commands as $command) {
98
            $arguments = [
99
                'command' => $command,
100
                'name' => $input->getArgument('name')
101
            ];
102
103
            switch ($command) {
104
                case 'create:controller':
105
                    $arguments['--camel'] = $input->getOption('camel');
106
                    $arguments['--doctrine'] = $input->getOption('doctrine');
107
                    $arguments['--keep'] = $input->getOption('keep');
108
                    $arguments['--lowercase'] = $input->getOption('lowercase');
109
                    $arguments['--wildfire'] = $input->getOption('wildfire');
110
111
                    break;
112
                case 'create:model':
113
                    $arguments['--camel'] = $input->getOption('camel');
114
                    $arguments['--doctrine'] = $input->getOption('doctrine');
115
                    $arguments['--lowercase'] = $input->getOption('lowercase');
116
                    $arguments['--wildfire'] = $input->getOption('wildfire');
117
118
                    break;
119
                case 'create:view':
120
                    $arguments['--bootstrap'] = $input->getOption('bootstrap');
121
                    $arguments['--camel'] = $input->getOption('camel');
122
                    $arguments['--keep'] = $input->getOption('keep');
123
124
                    break;
125
            }
126
127
            $input = new ArrayInput($arguments);
128
            $application = $this->getApplication()->find($command);
129
            $application->run($input, $output);
130
        }
131
    }
132
}
133