Completed
Push — master ( 8482f5...6f4e0b )
by max
02:05
created

Table::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace T4web\Migrations\Version;
4
5
use Zend\Db\Sql\Select;
6
use Zend\Db\TableGateway\TableGateway;
7
8
class Table
9
{
10
    /**
11
     * @var \Zend\Db\TableGateway\TableGateway
12
     */
13
    protected $tableGateway;
14
15
    public function __construct(TableGateway $tableGateway)
16
    {
17
        $this->tableGateway = $tableGateway;
18
    }
19
20
    public function save($version)
21
    {
22
        $this->tableGateway->insert(['version' => $version]);
23
        return $this->tableGateway->lastInsertValue;
24
    }
25
26
    public function delete($version)
27
    {
28
        $this->tableGateway->delete(['version' => $version]);
29
    }
30
31
    public function applied($version)
32
    {
33
        $result = $this->tableGateway->select(['version' => $version]);
34
        return $result->count() > 0;
35
    }
36
37
    public function getCurrentVersion()
38
    {
39
        $result = $this->tableGateway->select(function (Select $select) {
40
            $select->order('version DESC')->limit(1);
41
        });
42
        if (!$result->count()) {
43
            return 0;
44
        }
45
        return $result->current()->getVersion();
46
    }
47
}
48