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

MigrateDownCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Commands;
3
4
use Wandu\Console\Command;
5
use Wandu\Console\Exception\ConsoleException;
6
use RuntimeException;
7
use Wandu\Database\Migrator\Migrator;
8
9
class MigrateDownCommand extends Command
10
{
11
    /** @var string */
12
    protected $description = 'Execute targeted rollback.';
13
14
    /** @var array */
15
    protected $arguments = [
16
        'id' => 'the migrate id for the rollback',
17
    ];
18
    
19
    /** @var \Wandu\Database\Migrator\Migrator */
20
    protected $manager;
21
22
    /**
23
     * @param \Wandu\Database\Migrator\Migrator $manager
24
     */
25
    public function __construct(Migrator $manager)
26
    {
27
        $this->manager = $manager;
28
    }
29
30
    public function execute()
31
    {
32
        $id = $this->input->getArgument('id');
33
        try {
34
            $this->manager->down($id);
35
        } catch (RuntimeException $e) {
36
            throw new ConsoleException("<error>Error</error> {$e->getMessage()}");
37
        }
38
        $this->output->writeln("<info>down</info> {$id}");
39
    }
40
}
41