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

StatusCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
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 3 1
A execute() 0 17 4
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