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

MigrateStatusCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
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 MigrateStatusCommand extends Command
8
{
9
    /** @var string */
10
    protected $description = 'Show the status of all migrations.';
11
    
12
    /** @var \Wandu\Database\Migrator\Migrator */
13
    protected $manager;
14
15
    /**
16
     * @param \Wandu\Database\Migrator\Migrator $manager
17
     */
18
    public function __construct(Migrator $manager) {
19
        $this->manager = $manager;
20
    }
21
22
    public function execute()
23
    {
24
        $this->output->writeln(' STATUS   MIGRATION ID   MIGRATION NAME');
25
        $this->output->writeln('----------------------------------------');
26
        foreach ($this->manager->migrations() as $migration) {
27
            if ($migration->isApplied()) {
28
                $textFormat = " <info>%6s</info>   %s  <comment>%s</comment>";
29
            } else {
30
                $textFormat = " <error>%6s</error>   %s  <comment>%s</comment>";
31
            }
32
            $this->output->writeln(sprintf(
33
                $textFormat,
34
                $migration->isApplied() ? 'up  ' : 'down ',
35
                $migration->getId(),
36
                $migration->getName()
37
            ));
38
        }
39
    }
40
}
41