Completed
Push — master ( afaf42...8ac772 )
by Raffael
20:10 queued 16:21
created

Upgrade::start()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

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.7666
c 0
b 0
f 0
cc 2
crap 6
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
    public function __construct(Migration $migration, LoggerInterface $logger, GetOpt $getopt)
45
    {
46
        $this->migration = $migration;
47
        $this->logger = $logger;
48
        $this->getopt = $getopt;
49
    }
50
51
    /**
52
     * Start.
53
     */
54
    public function __invoke(): bool
55
    {
56
        $deltas = $this->getopt->getOption('delta');
57
        if ($deltas === null) {
58
            $deltas = [];
59
        } else {
60
            $deltas = explode(',', $deltas);
61
        }
62
63
        return $this->migration->start(
64
            (bool) $this->getopt->getOption('force'),
65
            (bool) $this->getopt->getOption('ignore'),
66
            $deltas
67
        );
68
    }
69
70
    // Get operands
71
    public static function getOperands(): array
72
    {
73
        return [];
74
    }
75
76
    /**
77
     * Get upgrade options.
78
     */
79
    public static function getOptions(): array
80
    {
81
        return [
82
            \GetOpt\Option::create('f', 'force')->setDescription('Force apply deltas even if a delta has already been applied before'),
83
            \GetOpt\Option::create('i', 'ignore')->setDescription('Do not abort if any error is encountered'),
84
            \GetOpt\Option::create('d', 'delta', \GetOpt\GetOpt::REQUIRED_ARGUMENT)->setDescription('Specify specific deltas (comma separated)'),
85
        ];
86
    }
87
}
88