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

UpCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Migrator\Commands;
3
4
use RuntimeException;
5
use Wandu\Console\Command;
6
use Wandu\Console\Exception\ConsoleException;
7
use Wandu\Database\Migrator\Migrator;
8
9
class UpCommand extends Command
10
{
11
    /** @var string */
12
    protected $description = 'Execute targeted migration.';
13
    
14
    /** @var array */
15
    protected $arguments = [
16
        'id' => 'the migrate id for the migration',
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->up($id);
35
        } catch (RuntimeException $e) {
36
            throw new ConsoleException("<error>Error</error> {$e->getMessage()}");
37
        }
38
        $this->output->writeln("<info>up</info> {$id}");
39
    }
40
}
41