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

StatusCommand::execute()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 5
nop 0
dl 0
loc 17
ccs 0
cts 17
cp 0
crap 20
rs 9.2
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