MigrateCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 4 1
A fire() 0 13 3
1
<?php
2
3
namespace Arrilot\BitrixMigrations\Commands;
4
5
use Arrilot\BitrixMigrations\Migrator;
6
7
class MigrateCommand extends AbstractCommand
8
{
9
    /**
10
     * Migrator instance.
11
     *
12
     * @var Migrator
13
     */
14
    protected $migrator;
15
16
    protected static $defaultName = 'migrate';
17
    /**
18
     * Constructor.
19
     *
20
     * @param Migrator    $migrator
21
     * @param string|null $name
22
     */
23
    public function __construct(Migrator $migrator, $name = null)
24
    {
25
        $this->migrator = $migrator;
26
27
        parent::__construct($name);
28
    }
29
30
    /**
31
     * Configures the current command.
32
     */
33
    protected function configure()
34
    {
35
        $this->setDescription('Run all outstanding migrations');
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return null|int
42
     */
43
    protected function fire()
44
    {
45
        $toRun = $this->migrator->getMigrationsToRun();
46
47
        if (!empty($toRun)) {
48
            foreach ($toRun as $migration) {
49
                $this->migrator->runMigration($migration);
50
                $this->message("<info>Migrated:</info> {$migration}.php");
51
            }
52
        } else {
53
            $this->info('Nothing to migrate');
54
        }
55
    }
56
}
57