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

MakeModelCommand::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 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
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\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 Model Command
13
 *
14
 * @package Combustor
15
 * @author  Rougin Royce Gutib <[email protected]>
16
 */
17
class MakeModelCommand 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:model')->setDescription('Create a new model class');
27 9
        $this->addArgument('table', InputArgument::REQUIRED, 'Name of the table');
28 9
        $this->addOption('type', null, InputArgument::OPTIONAL, 'Type of model: Either Credo or Wildfire', 'wildfire');
29 9
    }
30
31
    /**
32
     * Executes the current command.
33
     *
34
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
35
     * @param  \Symfony\Component\Console\Input\OutputInterface $output
36
     * @return void
37
     */
38 6
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40 6
        $modelType = 'Models/' . ucfirst($input->getOption('type'));
41 6
        $contents  = (new DataGenerator($this->describe, $input))->generate();
42 6
        $filename  = ucfirst(singular(underscore($input->getArgument('table'))));
43 6
        $rendered  = $this->renderer->render($modelType . '.twig', $contents);
44
45 6
        $this->filesystem->write('application/models/' . $filename . '.php', $rendered);
46
47 6
        $output->writeln('<info>Model created successfully!</info>');
48 6
    }
49
}
50