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

MigrateStatusCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 34
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 18 4
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