YarakCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 65
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMigrator() 0 10 1
A getMigratorClassName() 0 7 1
A getRepository() 0 9 1
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