Passed
Push — master ( 47e248...a43368 )
by Raffael
09:50
created

Upgrade::start()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
crap 6
eloc 10
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Cli\Console;
13
14
use Balloon\Migration;
15
use GetOpt\GetOpt;
16
use Psr\Log\LoggerInterface;
17
18
class Upgrade
19
{
20
    /**
21
     * Getopt.
22
     *
23
     * @var GetOpt
24
     */
25
    protected $getopt;
26
27
    /**
28
     * Logger.
29
     *
30
     * @var LoggerInterface
31
     */
32
    protected $logger;
33
34
    /**
35
     * Migration.
36
     *
37
     * @var Migration
38
     */
39
    protected $migration;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param Migration       $migration
45
     * @param LoggerInterface $logger
46
     * @param GetOpt          $getopt
47
     */
48
    public function __construct(Migration $migration, LoggerInterface $logger, GetOpt $getopt)
49
    {
50
        $this->migration = $migration;
51
        $this->logger = $logger;
52
        $this->getopt = $getopt;
53
    }
54
55
    /**
56
     * Start.
57
     *
58
     * @return bool
59
     */
60
    public function start(): bool
61
    {
62
        $deltas = $this->getopt->getOption('delta');
63
        if ($deltas === null) {
64
            $deltas = [];
65
        } else {
66
            $deltas = explode(',', $deltas);
67
        }
68
69
        return $this->migration->start(
70
            (bool) $this->getopt->getOption('force'),
71
            (bool) $this->getopt->getOption('ignore'),
72
            $deltas
73
        );
74
    }
75
}
76