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

MakeViewCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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 View Command
13
 *
14
 * @package Combustor
15
 * @author  Rougin Royce Gutib <[email protected]>
16
 */
17
class MakeViewCommand 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:view')->setDescription('Create a new view folder');
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 = strtolower(plural(underscore($input->getArgument('table'))));
41
42 6
        $views = [ 'create', 'edit', 'index', 'show' ];
43
44 6
        foreach ($views as $item) {
45 6
            $file = 'application/views/' . $filename . '/' . $item . '.php';
46 6
            $view = $this->renderer->render('Views/' . ucfirst($item) . '.twig', $contents);
47
48 6
            $this->filesystem->write($file, $view);
49 6
        }
50
51 6
        $output->writeln('<info>Views created successfully!</info>');
52 6
    }
53
}
54