Failed Conditions
Push — master ( 57b8db...ead074 )
by Jonathan
12s
created

MigrationTableStatus::isUpToDate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

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