Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
created

MigrateCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Migrator\Commands;
3
4
use Wandu\Console\Command;
5
use Wandu\Database\Migrator\MigrateManager;
6
use Wandu\DI\ContainerInterface;
7
8
class MigrateCommand extends Command
9
{
10
    /** @var string */
11
    protected $description = 'Run migrate.';
12
13
    /** @var \Wandu\DI\ContainerInterface */
14
    protected $container;
15
16
    /** @var \Wandu\Database\Migrator\MigrateManager */
17
    protected $manager;
18
19
    /**
20
     * @param \Wandu\DI\ContainerInterface $container
21
     * @param \Wandu\Database\Migrator\MigrateManager $manager
22
     */
23
    public function __construct(ContainerInterface $container, MigrateManager $manager)
24
    {
25
        $this->container = $container;
26
        $this->manager = $manager;
27
    }
28
29
    public function execute()
30
    {
31
        $migrations = $this->manager->getMigrations();
32
        $isNoMigration = true;
33
        foreach ($migrations as $migration) {
34
            if (!$migration->isApplied()) {
35
                $isNoMigration = false;
36
                $migration->up();
37
                $this->output->writeln(sprintf("<info>migrate</info> %s", $migration->getId()));
38
            }
39
        }
40
        if ($isNoMigration) {
41
            $this->output->writeln("<comment>there is no migration to migrate.</comment>");
42
        }
43
    }
44
}
45