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

MigrateStatusCommand::execute()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
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 3
nop 0
dl 0
loc 18
ccs 0
cts 18
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\MigrateManager;
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\MigrateManager */
13
    protected $manager;
14
15
    /**
16
     * @param \Wandu\Database\Migrator\MigrateManager $manager
17
     */
18
    public function __construct(MigrateManager $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->getMigrations() 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