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

SchemaException::viewAlreadyExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Doctrine\DBAL\Schema;
4
5
use Doctrine\DBAL\DBALException;
6
use function implode;
7
use function sprintf;
8
9
class SchemaException extends DBALException
10
{
11
    public const TABLE_DOESNT_EXIST       = 10;
12
    public const TABLE_ALREADY_EXISTS     = 20;
13
    public const COLUMN_DOESNT_EXIST      = 30;
14
    public const COLUMN_ALREADY_EXISTS    = 40;
15
    public const INDEX_DOESNT_EXIST       = 50;
16
    public const INDEX_ALREADY_EXISTS     = 60;
17
    public const SEQUENCE_DOENST_EXIST    = 70;
18
    public const SEQUENCE_ALREADY_EXISTS  = 80;
19
    public const INDEX_INVALID_NAME       = 90;
20
    public const FOREIGNKEY_DOESNT_EXIST  = 100;
21
    public const NAMESPACE_ALREADY_EXISTS = 110;
22
    public const VIEW_DOENST_EXIST        = 120;
23
    public const VIEW_ALREADY_EXISTS      = 130;
24
25
    /**
26
     * @param string $tableName
27
     *
28 19
     * @return \Doctrine\DBAL\Schema\SchemaException
29
     */
30 19
    public static function tableDoesNotExist($tableName)
31
    {
32
        return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST);
33
    }
34
35
    /**
36
     * @param string $indexName
37
     *
38 19
     * @return \Doctrine\DBAL\Schema\SchemaException
39
     */
40 19
    public static function indexNameInvalid($indexName)
41 19
    {
42 19
        return new self(
43
            sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName),
44
            self::INDEX_INVALID_NAME
45
        );
46
    }
47
48
    /**
49
     * @param string $indexName
50
     * @param string $table
51
     *
52 38
     * @return \Doctrine\DBAL\Schema\SchemaException
53
     */
54 38
    public static function indexDoesNotExist($indexName, $table)
55 38
    {
56 38
        return new self(
57
            sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table),
58
            self::INDEX_DOESNT_EXIST
59
        );
60
    }
61
62
    /**
63
     * @param string $indexName
64
     * @param string $table
65
     *
66 57
     * @return \Doctrine\DBAL\Schema\SchemaException
67
     */
68 57
    public static function indexAlreadyExists($indexName, $table)
69 57
    {
70 57
        return new self(
71
            sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table),
72
            self::INDEX_ALREADY_EXISTS
73
        );
74
    }
75
76
    /**
77
     * @param string $columnName
78
     * @param string $table
79
     *
80 76
     * @return \Doctrine\DBAL\Schema\SchemaException
81
     */
82 76
    public static function columnDoesNotExist($columnName, $table)
83 76
    {
84 76
        return new self(
85
            sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table),
86
            self::COLUMN_DOESNT_EXIST
87
        );
88
    }
89
90
    /**
91
     * @param string $namespaceName
92
     *
93 19
     * @return \Doctrine\DBAL\Schema\SchemaException
94
     */
95 19
    public static function namespaceAlreadyExists($namespaceName)
96 19
    {
97 19
        return new self(
98
            sprintf("The namespace with name '%s' already exists.", $namespaceName),
99
            self::NAMESPACE_ALREADY_EXISTS
100
        );
101
    }
102
103
    /**
104
     * @param string $tableName
105
     *
106 19
     * @return \Doctrine\DBAL\Schema\SchemaException
107
     */
108 19
    public static function tableAlreadyExists($tableName)
109
    {
110
        return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS);
111
    }
112
113
    /**
114
     * @param string $tableName
115
     * @param string $columnName
116
     *
117 19
     * @return \Doctrine\DBAL\Schema\SchemaException
118
     */
119 19
    public static function columnAlreadyExists($tableName, $columnName)
120 19
    {
121 19
        return new self(
122
            "The column '" . $columnName . "' on table '" . $tableName . "' already exists.",
123
            self::COLUMN_ALREADY_EXISTS
124
        );
125
    }
126
127
    /**
128
     * @param string $sequenceName
129
     *
130 19
     * @return \Doctrine\DBAL\Schema\SchemaException
131
     */
132 19
    public static function sequenceAlreadyExists($sequenceName)
133
    {
134
        return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS);
135
    }
136
137
    /**
138
     * @param string $sequenceName
139
     *
140 19
     * @return \Doctrine\DBAL\Schema\SchemaException
141
     */
142 19
    public static function sequenceDoesNotExist($sequenceName)
143
    {
144
        return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST);
145
    }
146
147
    /**
148
     * @param string $fkName
149
     * @param string $table
150
     *
151
     * @return \Doctrine\DBAL\Schema\SchemaException
152
     */
153
    public static function foreignKeyDoesNotExist($fkName, $table)
154
    {
155
        return new self(
156
            sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table),
157
            self::FOREIGNKEY_DOESNT_EXIST
158
        );
159
    }
160
161
    /**
162
     * @return \Doctrine\DBAL\Schema\SchemaException
163
     */
164
    public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
165
    {
166
        return new self(
167
            'The performed schema operation on ' . $localTable->getName() . ' requires a named foreign key, ' .
168
            'but the given foreign key from (' . implode(', ', $foreignKey->getColumns()) . ') onto foreign table ' .
169
            "'" . $foreignKey->getForeignTableName() . "' (" . implode(', ', $foreignKey->getForeignColumns()) . ') is currently ' .
170
            'unnamed.'
171
        );
172
    }
173
174
    /**
175
     * @param string $changeName
176
     *
177
     * @return \Doctrine\DBAL\Schema\SchemaException
178
     */
179
    public static function alterTableChangeNotSupported($changeName)
180
    {
181
        return new self(
182
            sprintf("Alter table change not supported, given '%s'", $changeName)
183
        );
184
    }
185
186
    /**
187
     * @param string $viewName
188
     *
189
     * @return \Doctrine\DBAL\Schema\SchemaException
190
     */
191
    public static function viewAlreadyExists($viewName)
192
    {
193
        return new self("The view '" . $viewName . "' already exists.", self::VIEW_ALREADY_EXISTS);
194
    }
195
196
    /**
197
     * @param string $viewName
198
     *
199
     * @return \Doctrine\DBAL\Schema\SchemaException
200
     */
201
    public static function viewDoesNotExist($viewName)
202
    {
203
        return new self("There exists no view with the name '" . $viewName . "'.", self::VIEW_DOENST_EXIST);
204
    }
205
}
206