Completed
Push — master ( f5a493...f6c233 )
by Joao
03:20
created

AbstractCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDbDataset() 0 4 1
A getVersion() 0 4 1
A setVersion() 0 4 1
A checkExistsVersion() 0 8 2
1
<?php
2
3
namespace ByJG\DbMigration\Commands;
4
5
use ByJG\AnyDataset\Repository\DBDataset;
6
7
abstract class AbstractCommand implements CommandInterface
8
{
9
    /**
10
     * @var DBDataset
11
     */
12
    private $_dbDataset;
13
14
    /**
15
     * Command constructor.
16
     *
17
     * @param DBDataset $_dbDataset
18
     */
19
    public function __construct(DBDataset $_dbDataset)
20
    {
21
        $this->_dbDataset = $_dbDataset;
22
    }
23
24
    /**
25
     * @return DBDataset
26
     */
27
    public function getDbDataset()
28
    {
29
        return $this->_dbDataset;
30
    }
31
32
    public function getVersion()
33
    {
34
        return $this->getDbDataset()->getScalar('SELECT version FROM migration_version');
35
    }
36
37
    public function setVersion($version)
38
    {
39
        $this->getDbDataset()->execSQL('UPDATE migration_version SET version = :version', ['version' => $version]);
40
    }
41
42
    protected function checkExistsVersion()
43
    {
44
        // Get the version to check if exists
45
        $version = $this->getVersion();
46
        if ($version === false) {
47
            $this->getDbDataset()->execSQL('insert into migration_version values(0)');
48
        }
49
    }
50
}
51