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

MakeModelCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 2
cbo 6
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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