Passed
Pull Request — master (#65)
by Arman
06:20 queued 03:21
created

MigrationMigrateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A exec() 0 12 5
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.7.0
13
 */
14
15
namespace Quantum\Console\Commands;
16
17
use Quantum\Exceptions\MigrationException;
18
use Quantum\Migration\MigrationManager;
19
use Quantum\Console\QtCommand;
20
21
/**
22
 * Class MigrationMigrateCommand
23
 * @package Quantum\Console\Command
24
 */
25
class MigrationMigrateCommand extends QtCommand
26
{
27
28
    /**
29
     * The console command name.
30
     * @var string
31
     */
32
    protected $name = 'migration:migrate';
33
34
    /**
35
     * The console command description.
36
     * @var string
37
     */
38
    protected $description = 'Migrates the migrations';
39
40
    /**
41
     * Command arguments
42
     * @var \string[][]
43
     */
44
    protected $args = [
45
        ['direction', 'optional', '[up] for upgrade, [down] for downgrade'],
46
    ];
47
    protected $options = [
48
        ['step', 's', 'optional', 'Number of migrations to apply'],
49
    ];
50
51
    /**
52
     * Executes the command
53
     */
54
    public function exec()
55
    {
56
        $direction = $this->getArgument('direction') ?: MigrationManager::UPGRADE;
57
        $step = (int) $this->getOption('step') ?: null;
58
59
        $migrationManager = new MigrationManager();
60
61
        try {
62
            $migrated = $migrationManager->applyMigrations($direction, $step);
63
            $this->info($migrated . ' migration' . ($migrated > 1 ? 's were' : ' was') . ' applied');
64
        } catch (MigrationException $e) {
65
            $this->info($e->getMessage());
66
        }
67
    }
68
69
}
70