Table   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 5 1
A delete() 0 4 1
A applied() 0 5 1
A getCurrentVersion() 0 10 2
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->getLastInsertValue();
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