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

StatusCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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