Completed
Push — master ( 348067...ae37c1 )
by Zach
03:29 queued 01:39
created

MakeMigration::getCreator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
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
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class MakeMigration extends YarakCommand
12
{
13
    /**
14
     * Configure the command.
15
     */
16
    protected function configure()
17
    {
18
        $this->setName('make:migration')
19
            ->setDescription('Create a new migration file.')
20
            ->setHelp('This command allows you to make migration files.')
21
            ->addArgument(
22
                'name',
23
                InputArgument::REQUIRED,
24
                'The name of your migration, words separated by underscores.')
25
            ->addOption(
26
                'create',
27
                'c',
28
                InputOption::VALUE_REQUIRED,
29
                'The name of the table to create.'
30
            );
31
    }
32
33
    /**
34
     * Execute the command.
35
     *
36
     * @param InputInterface  $input
37
     * @param OutputInterface $output
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $name = $input->getArgument('name');
42
43
        $create = is_null($create = $input->getOption('create')) ? false : $create;
44
45
        $config = Config::getInstance($this->configArray);
46
47
        $creator = $this->getCreator($config);
48
49
        $creator->create($name, $create);
50
51
        $output->writeln("<info>Successfully created migration {$name}.</info>");
52
    }
53
54
    /**
55
     * Get a the migration creator class.
56
     *
57
     * @param Config $config
58
     *
59
     * @return Yarak\Migrations\MigrationCreator
60
     */
61
    protected function getCreator(Config $config)
62
    {
63
        $migratorType = ucfirst($config->get('migratorType'));
64
65
        $name = "Yarak\\Migrations\\{$migratorType}\\{$migratorType}MigrationCreator";
66
67
        return new $name($config);
68
    }
69
}
70