YarakCommand::getMigrator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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