Completed
Branch master (3adcdb)
by Raffael
08:09 queued 04:17
created

Upgrade   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getDescription() 0 4 1
A start() 0 15 2
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 as Migrator;
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 Migrator
38
     */
39
    protected $migration;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param Migrator        $migration
45
     * @param LoggerInterface $logger
46
     * @param GetOpt          $getopt
47
     */
48
    public function __construct(Migrator $migration, LoggerInterface $logger, GetOpt $getopt)
49
    {
50
        $this->migration = $migration;
51
        $this->logger = $logger;
52
        $this->getopt = $getopt;
53
    }
54
55
    /**
56
     * Get description.
57
     *
58
     * @return string
59
     */
60
    public function getDescription(): string
61
    {
62
        return 'Execute migration scripts between upgrades';
63
    }
64
65
    /**
66
     * Start.
67
     *
68
     * @return bool
69
     */
70
    public function start(): bool
71
    {
72
        $deltas = $this->getopt->getOption('delta');
73
        if ($deltas === null) {
74
            $deltas = [];
75
        } else {
76
            $deltas = explode(',', $deltas);
77
        }
78
79
        return $this->migration->start(
80
            (bool) $this->getopt->getOption('force'),
81
            (bool) $this->getopt->getOption('ignore'),
82
            $deltas
83
        );
84
    }
85
}
86