Failed Conditions
Pull Request — master (#707)
by Jonathan
03:12
created

TableStatus   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setCreated() 0 3 1
A setUpToDate() 0 3 1
A isUpToDate() 0 20 4
A isCreated() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tracking;
6
7
use Doctrine\DBAL\Schema\AbstractSchemaManager;
8
9
class TableStatus
10
{
11
    /** @var AbstractSchemaManager */
12
    private $schemaManager;
13
14
    /** @var TableDefinition */
15
    private $migrationTable;
16
17
    /** @var bool|null */
18
    private $created;
19
20
    /** @var bool|null */
21
    private $upToDate;
22
23 82
    public function __construct(
24
        AbstractSchemaManager $schemaManager,
25
        TableDefinition $migrationTable
26
    ) {
27 82
        $this->schemaManager  = $schemaManager;
28 82
        $this->migrationTable = $migrationTable;
29 82
    }
30
31 76
    public function setCreated(bool $created) : void
32
    {
33 76
        $this->created = $created;
34 76
    }
35
36 79
    public function isCreated() : bool
37
    {
38 79
        if ($this->created !== null) {
39 65
            return $this->created;
40
        }
41
42 78
        $this->created = $this->schemaManager->tablesExist([$this->migrationTable->getName()]);
43
44 78
        return $this->created;
45
    }
46
47 2
    public function setUpToDate(bool $upToDate) : void
48
    {
49 2
        $this->upToDate = $upToDate;
50 2
    }
51
52 62
    public function isUpToDate() : bool
53
    {
54 62
        if ($this->upToDate !== null) {
55 53
            return $this->upToDate;
56
        }
57
58 61
        $table = $this->schemaManager->listTableDetails($this->migrationTable->getName());
59
60 61
        $this->upToDate = true;
61
62 61
        foreach ($this->migrationTable->getColumnNames() as $columnName) {
63 61
            if ($table->hasColumn($columnName)) {
64 61
                continue;
65
            }
66
67 2
            $this->upToDate = false;
68 2
            break;
69
        }
70
71 61
        return $this->upToDate;
72
    }
73
}
74