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

UpCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 6
rs 9.4285
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