Completed
Push — master ( 4deee6...b383ba )
by Zach
05:43 queued 03:44
created

YarakCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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 Yarak\Console\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($this->config);
0 ignored issues
show
Unused Code introduced by
The call to YarakCommand::getMigratorClassName() has too many arguments starting with $this->config.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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