Failed Conditions
Pull Request — master (#3233)
by Sergey
10:50
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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Schema\Visitor;
21
22
use Doctrine\DBAL\Platforms\AbstractPlatform;
23
use Doctrine\DBAL\Schema\Table;
24
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
25
use Doctrine\DBAL\Schema\Sequence;
26
use function array_merge;
27
use Doctrine\DBAL\Schema\View;
28
29
class CreateSchemaSqlCollector extends AbstractVisitor
30
{
31
    /**
32
     * @var array
33
     */
34
    private $createNamespaceQueries = [];
35
36
    /**
37
     * @var array
38
     */
39
    private $createTableQueries = [];
40
41
    /**
42
     * @var array
43
     */
44
    private $createSequenceQueries = [];
45
46
    /**
47
     * @var array
48
     */
49
    private $createFkConstraintQueries = [];
50
51
    /**
52
     * @var array
53
     */
54
    private $createViewQueries = [];
55
56
    /**
57
     *
58
     * @var \Doctrine\DBAL\Platforms\AbstractPlatform
59
     */
60
    private $platform = null;
61
62
    /**
63
     * @param AbstractPlatform $platform
64
     */
65 351
    public function __construct(AbstractPlatform $platform)
66
    {
67 351
        $this->platform = $platform;
68 351
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 80
    public function acceptNamespace($namespaceName)
74
    {
75 80
        if ($this->platform->supportsSchemas()) {
76 40
            $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
77
        }
78 80
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 271
    public function acceptTable(Table $table)
84
    {
85 271
        $this->createTableQueries = array_merge($this->createTableQueries, (array) $this->platform->getCreateTableSQL($table));
86 271
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 60
    public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
92
    {
93 60
        if ($this->platform->supportsForeignKeyConstraints()) {
94 60
            $this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable);
95
        }
96 60
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101 60
    public function acceptSequence(Sequence $sequence)
102
    {
103 60
        $this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence);
104 60
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109 40
    public function acceptView(View $view)
110
    {
111 40
        $this->createViewQueries[] = $this->platform->getCreateViewSQL($view->getName(), $view->getSql());
112 40
    }
113
114
    /**
115
     * @return void
116
     */
117 20
    public function resetQueries()
118
    {
119 20
        $this->createNamespaceQueries = [];
120 20
        $this->createTableQueries = [];
121 20
        $this->createSequenceQueries = [];
122 20
        $this->createFkConstraintQueries = [];
123 20
        $this->createViewQueries = [];
124 20
    }
125
126
    /**
127
     * Gets all queries collected so far.
128
     *
129
     * @return array
130
     */
131 351
    public function getQueries()
132
    {
133 351
        return array_merge(
134 351
            $this->createNamespaceQueries,
135 351
            $this->createTableQueries,
136 351
            $this->createSequenceQueries,
137 351
            $this->createFkConstraintQueries,
138 351
            $this->createViewQueries
139
        );
140
    }
141
}
142