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

Migration   A

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 migrate() 0 6 2
A __construct() 0 3 1
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