Failed Conditions
Pull Request — develop (#3348)
by Sergei
65:20
created

SchemaException::namedForeignKeyRequired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Doctrine\DBAL\Schema;
4
5
use Doctrine\DBAL\DBALException;
6
use function sprintf;
7
8
class SchemaException extends DBALException
9
{
10
    public const TABLE_DOESNT_EXIST       = 10;
11
    public const TABLE_ALREADY_EXISTS     = 20;
12
    public const COLUMN_DOESNT_EXIST      = 30;
13
    public const COLUMN_ALREADY_EXISTS    = 40;
14
    public const INDEX_DOESNT_EXIST       = 50;
15
    public const INDEX_ALREADY_EXISTS     = 60;
16
    public const SEQUENCE_DOENST_EXIST    = 70;
17
    public const SEQUENCE_ALREADY_EXISTS  = 80;
18
    public const INDEX_INVALID_NAME       = 90;
19
    public const FOREIGNKEY_DOESNT_EXIST  = 100;
20
    public const CONSTRAINT_DOESNT_EXIST  = 110;
21
    public const NAMESPACE_ALREADY_EXISTS = 120;
22
23
    public static function tableDoesNotExist(string $tableName) : self
24
    {
25
        return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST);
26
    }
27
28
    public static function indexNameInvalid(string $indexName) : self
29 23
    {
30
        return new self(
31 23
            sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName),
32
            self::INDEX_INVALID_NAME
33
        );
34
    }
35
36
    public static function indexDoesNotExist(string $indexName, string $table) : self
37
    {
38
        return new self(
39 23
            sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table),
40
            self::INDEX_DOESNT_EXIST
41 23
        );
42 23
    }
43 23
44
    public static function indexAlreadyExists(string $indexName, string $table) : self
45
    {
46
        return new self(
47
            sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table),
48
            self::INDEX_ALREADY_EXISTS
49
        );
50
    }
51
52
    public static function columnDoesNotExist(string $columnName, string $table) : self
53 46
    {
54
        return new self(
55 46
            sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table),
56 46
            self::COLUMN_DOESNT_EXIST
57 46
        );
58
    }
59
60
    public static function namespaceAlreadyExists(string $namespaceName) : self
61
    {
62
        return new self(
63
            sprintf("The namespace with name '%s' already exists.", $namespaceName),
64
            self::NAMESPACE_ALREADY_EXISTS
65
        );
66
    }
67 69
68
    public static function tableAlreadyExists(string $tableName) : self
69 69
    {
70 69
        return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS);
71 69
    }
72
73
    public static function columnAlreadyExists(string $tableName, string $columnName) : self
74
    {
75
        return new self(
76
            "The column '" . $columnName . "' on table '" . $tableName . "' already exists.",
77
            self::COLUMN_ALREADY_EXISTS
78
        );
79
    }
80
81 92
    public static function sequenceAlreadyExists(string $sequenceName) : self
82
    {
83 92
        return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS);
84 92
    }
85 92
86
    public static function sequenceDoesNotExist(string $sequenceName) : self
87
    {
88
        return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST);
89
    }
90
91
    public static function uniqueConstraintDoesNotExist(string $constraintName, string $table) : self
92
    {
93
        return new self(sprintf(
94 23
            'There exists no unique constraint with the name "%s" on table "%s".',
95
            $constraintName,
96 23
            $table
97 23
        ), self::CONSTRAINT_DOESNT_EXIST);
98 23
    }
99
100
    public static function foreignKeyDoesNotExist(string $fkName, string $table) : self
101
    {
102
        return new self(
103
            sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table),
104
            self::FOREIGNKEY_DOESNT_EXIST
105
        );
106
    }
107 23
108
    public static function assetDoesNotHaveAName(AbstractAsset $asset) : self
0 ignored issues
show
Unused Code introduced by
The parameter $asset is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

108
    public static function assetDoesNotHaveAName(/** @scrutinizer ignore-unused */ AbstractAsset $asset) : self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109 23
    {
110
        return new self('The asset does not have a name');
111
    }
112
113
    public static function alterTableChangeNotSupported(string $changeName) : self
114
    {
115
        return new self(
116
            sprintf("Alter table change not supported, given '%s'", $changeName)
117
        );
118 23
    }
119
}
120