Completed
Push — dev ( 4deee6...a8b68f )
by Zach
02:10
created

YarakCommand::getMigratorClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Yarak\Commands;
4
5
use Yarak\Config\Config;
6
use Yarak\Output\SymfonyOutput;
7
use Yarak\DB\ConnectionResolver;
8
use Symfony\Component\Console\Command\Command;
9
10
class YarakCommand extends Command
11
{
12
    /**
13
     * Application config.
14
     *
15
     * @var array
16
     */
17
    protected $configArray;
18
19
    /**
20
     * Construct.
21
     *
22
     * @param array $configArray
23
     */
24
    public function __construct(array $configArray)
25
    {
26
        parent::__construct();
27
28
        $this->configArray = $configArray;
29
    }
30
31
32
    /**
33
     * Get an instance of the migrator.
34
     *
35
     * @param SymfonyOutput $symfonyOutput
36
     *
37
     * @return Migrator
38
     */
39
    protected function getMigrator(SymfonyOutput $symfonyOutput)
40
    {
41
        $config = Config::getInstance($this->configArray);
42
43
        $migratorClassName = $this->getMigratorClassName($config);
44
45
        return new $migratorClassName(
46
            $config,
47
            new ConnectionResolver(),
48
            $this->getRepository($config),
49
            $symfonyOutput
50
        );
51
    }
52
53
    /**
54
     * Get the name of the migrator class.
55
     *
56
     * @param Config $config
57
     *
58
     * @return string
59
     */
60
    protected function getMigratorClassName(Config $config)
61
    {
62
        $migratorType = ucfirst($config->get('migratorType'));
63
64
        return "Yarak\\Migrations\\$migratorType\\".
65
            $migratorType.'Migrator';
66
    }
67
68
    /**
69
     * Get an instance of MigrationRepository.
70
     *
71
     * @param Config $config
72
     *
73
     * @return Yarak\Migrations\MigrationRepository
74
     */
75
    protected function getRepository(Config $config)
76
    {
77
        $repositoryType = ucfirst($config->get('migrationRepository'));
78
79
        $repositoryClass = 'Yarak\\Migrations\\Repositories\\'.
80
            $repositoryType.'MigrationRepository';
81
82
        return new $repositoryClass();
83
    }
84
}
85