Completed
Pull Request — master (#3233)
by Sergey
65:15
created

CreateSchemaSqlCollector::acceptView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Doctrine\DBAL\Schema\Visitor;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
7
use Doctrine\DBAL\Schema\Sequence;
8
use Doctrine\DBAL\Schema\Table;
9
use Doctrine\DBAL\Schema\View;
10
use function array_merge;
11
12
class CreateSchemaSqlCollector extends AbstractVisitor
13
{
14
    /** @var string[] */
15
    private $createNamespaceQueries = [];
16
17
    /** @var string[] */
18
    private $createTableQueries = [];
19
20
    /** @var string[] */
21
    private $createSequenceQueries = [];
22
23
    /** @var string[] */
24
    private $createFkConstraintQueries = [];
25
26
    /** @var string[] */
27
    private $createViewQueries = [];
28 314
29
    /** @var AbstractPlatform */
30 314
    private $platform = null;
31 314
32
    public function __construct(AbstractPlatform $platform)
33
    {
34
        $this->platform = $platform;
35
    }
36 76
37
    /**
38 76
     * {@inheritdoc}
39 57
     */
40
    public function acceptNamespace($namespaceName)
41
    {
42 38
        if (! $this->platform->supportsSchemas()) {
43 38
            return;
44
        }
45
46
        $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
47
    }
48 257
49
    /**
50 257
     * {@inheritdoc}
51 257
     */
52
    public function acceptTable(Table $table)
53
    {
54
        $this->createTableQueries = array_merge($this->createTableQueries, (array) $this->platform->getCreateTableSQL($table));
55
    }
56 57
57
    /**
58 57
     * {@inheritdoc}
59 19
     */
60
    public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
61
    {
62 57
        if (! $this->platform->supportsForeignKeyConstraints()) {
63 57
            return;
64
        }
65
66
        $this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable);
67
    }
68 57
69
    /**
70 57
     * {@inheritdoc}
71 57
     */
72
    public function acceptSequence(Sequence $sequence)
73
    {
74
        $this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence);
75
    }
76 19
77
    /**
78 19
     * {@inheritdoc}
79 19
     */
80 19
    public function acceptView(View $view)
81 19
    {
82 19
        $this->createViewQueries[] = $this->platform->getCreateViewSQL($view->getName(), $view->getSql());
83
    }
84
85
    /**
86
     * @return void
87
     */
88
    public function resetQueries()
89 314
    {
90
        $this->createNamespaceQueries    = [];
91 314
        $this->createTableQueries        = [];
92 314
        $this->createSequenceQueries     = [];
93 314
        $this->createFkConstraintQueries = [];
94 314
        $this->createViewQueries         = [];
95 314
    }
96
97
    /**
98
     * Gets all queries collected so far.
99
     *
100
     * @return string[]
101
     */
102
    public function getQueries()
103
    {
104
        return array_merge(
105
            $this->createNamespaceQueries,
106
            $this->createTableQueries,
107
            $this->createSequenceQueries,
108
            $this->createFkConstraintQueries,
109
            $this->createViewQueries
110
        );
111
    }
112
}
113