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

MigrateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 20
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 5 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\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