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

AbstractCommand::checkExistsVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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