Completed
Push — master ( dc7866...8155ff )
by Changwan
06:46
created

MigrateCommand::execute()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 6
nop 0
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\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->migrations();
23
        $isNoMigration = true;
24
        foreach ($migrations as $migration) {
25
            if (!$migration->isApplied()) {
26
                $isNoMigration = false;
27
                $migration->up();
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