Passed
Pull Request — master (#3233)
by Sergey
12:33
created

CreateSchemaSqlCollector::acceptView()   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
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
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 function array_merge;
10
use Doctrine\DBAL\Schema\View;
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
29
    /** @var AbstractPlatform */
30
    private $platform = null;
31
32 351
    public function __construct(AbstractPlatform $platform)
33
    {
34 351
        $this->platform = $platform;
35 351
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 80
    public function acceptNamespace($namespaceName)
41
    {
42 80
        if (! $this->platform->supportsSchemas()) {
43 60
            return;
44
        }
45
46 40
        $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
47 40
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 271
    public function acceptTable(Table $table)
53
    {
54 271
        $this->createTableQueries = array_merge($this->createTableQueries, (array) $this->platform->getCreateTableSQL($table));
55 271
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 60
    public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
61
    {
62 60
        if (! $this->platform->supportsForeignKeyConstraints()) {
63 20
            return;
64
        }
65
66 60
        $this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable);
67 60
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 60
    public function acceptSequence(Sequence $sequence)
73
    {
74 60
        $this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence);
75 60
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 40
    public function acceptView(View $view)
81
    {
82 40
        $this->createViewQueries[] = $this->platform->getCreateViewSQL($view->getName(), $view->getSql());
83 40
    }
84
85
    /**
86
     * @return void
87
     */
88 20
    public function resetQueries()
89
    {
90 20
        $this->createNamespaceQueries    = [];
91 20
        $this->createTableQueries        = [];
92 20
        $this->createSequenceQueries     = [];
93 20
        $this->createFkConstraintQueries = [];
94 20
        $this->createViewQueries = [];
95 20
    }
96
97
    /**
98
     * Gets all queries collected so far.
99
     *
100
     * @return string[]
101
     */
102 351
    public function getQueries()
103
    {
104 351
        return array_merge(
105 351
            $this->createNamespaceQueries,
106 351
            $this->createTableQueries,
107 351
            $this->createSequenceQueries,
108 351
            $this->createFkConstraintQueries,
109 351
            $this->createViewQueries
110
        );
111
    }
112
}
113