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

TableStatus::isCreated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
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