Start::process()   A
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 17
rs 9.2222
c 0
b 0
f 0
cc 6
nc 10
nop 0
1
<?php
2
3
namespace Vados\MigrationRunner;
4
5
use Phalcon\Db\Adapter\Pdo\Factory;
6
use Phalcon\Di;
7
use Phalcon\Mvc\Model\Manager;
8
use Phalcon\Mvc\Model\MetaData\Memory;
9
use Vados\MigrationRunner\command\Create;
10
use Vados\MigrationRunner\command\Down;
11
use Vados\MigrationRunner\command\GenerateConfigWizard;
12
use Vados\MigrationRunner\command\Help;
13
use Vados\MigrationRunner\command\Up;
14
use Vados\MigrationRunner\enum\Command;
15
use Vados\MigrationRunner\providers\PathProvider;
16
17
/**
18
 * Class Start
19
 * @package Vados\MigrationRunner
20
 */
21
class Start
22
{
23
    /**
24
     * @var string
25
     */
26
    private $command;
27
28
    /**
29
     * @var array
30
     */
31
    private $params = [];
32
33
    /**
34
     * Start constructor.
35
     * @param array $argv
36
     */
37
    public function __construct(array $argv)
38
    {
39
        if (array_key_exists(1, $argv)) {
40
            $this->command = $argv[1];
41
        } else {
42
            $this->command = 'help';
43
        }
44
        $this->params = array_splice($argv, 2);
45
        $di = new Di();
46
        $di->setShared('db', function() {
47
            return Factory::load(require PathProvider::getConfig());
48
        });
49
        $di->set('modelsManager', new Manager());
50
        $di->set('modelsMetadata', new Memory());
51
    }
52
53
    public function process() {
54
        if (!file_exists(PathProvider::getConfig())) {
55
            (new GenerateConfigWizard())->run();
56
        }
57
        switch ($this->command) {
58
            case Command::HELP:
59
                (new Help())->run();
60
                break;
61
            case Command::CREATE:
62
                (new Create($this->params))->run();
63
                break;
64
            case Command::UP:
65
                (new Up($this->params))->run();
66
                break;
67
            case Command::DOWN:
68
                (new Down($this->params))->run();
69
                break;
70
        }
71
    }
72
}