Migration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 60
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A migrate() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Component\Db;
6
7
use Nymfonya\Component\Container;
8
9
abstract class Migration extends Core
10
{
11
12
    /**
13
     * container
14
     *
15
     * @var Container
16
     */
17
    protected $container;
18
19
    /**
20
     * instanciate
21
     *
22
     * @param Container $container
23
     */
24 3
    public function __construct(Container $container)
25
    {
26 3
        parent::__construct($container);
27
    }
28
29
    /**
30
     * run migration for a given repository
31
     *
32
     * @return Migration
33
     */
34 3
    public function migrate(): Migration
35
    {
36 3
        if ($this->canMigrate()) {
37 3
            $this->runCreate()->runInsert()->runIndex();
38
        }
39 3
        return $this;
40
    }
41
42
    /**
43
     * check if migration can run
44
     *
45
     * @return boolean
46
     */
47
    abstract protected function canMigrate(): bool;
48
49
    /**
50
     * process create table
51
     *
52
     * @return string
53
     */
54
    abstract protected function runCreate(): Migration;
55
56
    /**
57
     * process insert into table
58
     *
59
     * @return string
60
     */
61
    abstract protected function runInsert(): Migration;
62
63
    /**
64
     * process alter index table
65
     *
66
     * @return string
67
     */
68
    abstract protected function runIndex(): Migration;
69
}
70