Completed
Push — master ( c889ea...14eda7 )
by Pierre
03:04
created

Migration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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
    public function __construct(Container $container)
23
    {
24
        parent::__construct($container);
25
    }
26
27
    /**
28
     * run migration for a given repository
29
     *
30
     * @return Migration
31
     */
32 4
    public function migrate(): Migration
33
    {
34 4
        if ($this->canMigrate()) {
35 4
            $this->runCreate()->runInsert();
36
        }
37 4
        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