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

UpCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 10 2
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