Completed
Push — master ( b31514...603a9f )
by Changwan
06:16
created

MigrateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 15 4
1
<?php
2
namespace Wandu\Database\Migrator\Commands;
3
4
use Wandu\Console\Command;
5
use Wandu\Database\Migrator\Migrator;
6
7
class MigrateCommand extends Command
8
{
9
    /** @var string */
10
    protected $description = 'Run migrate.';
11
12
    /** @var \Wandu\Database\Migrator\Migrator */
13
    protected $manager;
14
15
    public function __construct(Migrator $manager)
16
    {
17
        $this->manager = $manager;
18
    }
19
20
    public function execute()
21
    {
22
        $migrations = $this->manager->getMigrationInformations();
23
        $isNoMigration = true;
24
        foreach ($migrations as $migration) {
25
            if (!$this->manager->isApplied($migration)) {
26
                $isNoMigration = false;
27
                $this->manager->up($migration->getId());
28
                $this->output->writeln(sprintf("<info>up</info> %s", $migration->getId()));
29
            }
30
        }
31
        if ($isNoMigration) {
32
            $this->output->writeln("<comment>there is no migration to migrate.</comment>");
33
        }
34
    }
35
}
36