Failed Conditions
Pull Request — master (#675)
by Jonathan
06:31
created

MigrationTableStatus::setUpToDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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