Passed
Push — master ( 7248ab...0a52e0 )
by Pierre
10:18
created

Migration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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