Failed Conditions
Push — master ( c24352...310518 )
by Jonathan
16s
created

TableManipulator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
B createMigrationTable() 0 27 4
A __construct() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tracking;
6
7
use Doctrine\DBAL\Schema\AbstractSchemaManager;
8
use Doctrine\Migrations\Configuration\Configuration;
9
10
/**
11
 * @internal
12
 */
13
class TableManipulator
14
{
15
    /** @var Configuration */
16
    private $configuration;
17
18
    /** @var AbstractSchemaManager */
19
    private $schemaManager;
20
21
    /** @var TableDefinition */
22
    private $migrationTable;
23
24
    /** @var TableStatus */
25
    private $migrationTableStatus;
26
27
    /** @var TableUpdater */
28
    private $migrationTableUpdater;
29
30 79
    public function __construct(
31
        Configuration $configuration,
32
        AbstractSchemaManager $schemaManager,
33
        TableDefinition $migrationTable,
34
        TableStatus $migrationTableStatus,
35
        TableUpdater $migrationTableUpdater
36
    ) {
37 79
        $this->configuration         = $configuration;
38 79
        $this->schemaManager         = $schemaManager;
39 79
        $this->migrationTable        = $migrationTable;
40 79
        $this->migrationTableStatus  = $migrationTableStatus;
41 79
        $this->migrationTableUpdater = $migrationTableUpdater;
42 79
    }
43
44 79
    public function createMigrationTable() : bool
45
    {
46 79
        $this->configuration->validate();
47
48 79
        if ($this->configuration->isDryRun()) {
49 1
            return false;
50
        }
51
52 79
        if ($this->migrationTableStatus->isCreated()) {
53 60
            if (! $this->migrationTableStatus->isUpToDate()) {
54 2
                $this->migrationTableUpdater->updateMigrationTable();
55
56 2
                $this->migrationTableStatus->setUpToDate(true);
57
58 2
                return true;
59
            }
60
61 58
            return false;
62
        }
63
64 76
        $table = $this->migrationTable->getNewDBALTable();
65
66 76
        $this->schemaManager->createTable($table);
67
68 76
        $this->migrationTableStatus->setCreated(true);
69
70 76
        return true;
71
    }
72
}
73