Completed
Push — dev ( 6d8737...fe3822 )
by Zach
02:19
created

MakeMigration::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Commands;
4
5
use Yarak\Config\Config;
6
use Symfony\Component\Console\Input\InputOption;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class MakeMigration extends YarakCommand
10
{
11
    /**
12
     * Configure the command.
13
     */
14
    protected function configure()
15
    {
16
        $this->setName('make:migration')
17
            ->setDescription('Create a new migration file.')
18
            ->setHelp('This command allows you to make migration files.')
19
            ->addArgument(
20
                'name',
21
                InputArgument::REQUIRED,
22
                'The name of your migration, words separated by underscores.')
23
            ->addOption(
24
                'create',
25
                'c',
26
                InputOption::VALUE_REQUIRED,
27
                'The name of the table to create.'
28
            );
29
    }
30
31
    /**
32
     * Handle the command.
33
     */
34
    protected function handle()
35
    {
36
        $creator = $this->getCreator();
37
38
        $create = is_null($create = $this->option('create')) ? false : $create;
39
40
        $creator->create($this->argument('name'), $create);
41
    }
42
43
    /**
44
     * Get a the migration creator class.
45
     *
46
     * @return Yarak\Migrations\MigrationCreator
47
     */
48
    protected function getCreator()
49
    {
50
        $config = Config::getInstance($this->configArray);
51
52
        $migratorType = ucfirst($config->get('migratorType'));
53
54
        $name = "Yarak\\Migrations\\{$migratorType}\\{$migratorType}MigrationCreator";
55
56
        return new $name($config, $this->getOutput());
57
    }
58
}
59