AbstractMigration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 36
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getNumber() 0 8 3
up() 0 1 ?
A down() 0 3 1
1
<?php declare(strict_types=1);
2
/**
3
 * Starlit Db.
4
 *
5
 * @copyright Copyright (c) 2019 Starweb AB
6
 * @license   BSD 3-Clause
7
 */
8
9
namespace Starlit\Db\Migration;
10
11
use Starlit\Db\Db;
12
13
/**
14
 * Concrete migration class names must contain a sequential migration number, eg. "Migration1".
15
 *
16
 * Names can also include something more meaningful, eg. "Migration14CreateAuthorsTable".
17
 *
18
 * @author Andreas Nilsson <http://github.com/jandreasn>
19
 */
20
abstract class AbstractMigration
21
{
22
    /**
23
     * @var Db;
24
     */
25
    protected $db;
26
27
    /**
28
     * @param Db $db
29
     */
30 12
    final public function __construct(Db $db)
31
    {
32 12
        $this->db = $db;
33 12
    }
34
35 9
    public function getNumber(): int
36
    {
37 9
        if (!preg_match('/\d+/', get_class($this), $matches) ||  !($number = (int) $matches[0])) {
38 1
            throw new \LogicException("Invalid migration class name (must include a migration number)");
39
        }
40
41 8
        return $number;
42
    }
43
44
    /**
45
     * Actions to be performed when migrating up to this version (e.g. 6.1.0 -> 6.2.0)
46
     */
47
    abstract public function up(): void;
48
49
    /**
50
     * Actions to be performed when migrating down from this version (e.g. 6.2.0 -> 6.0.0)
51
     */
52 2
    public function down(): void
53
    {
54 2
    }
55
}
56