Completed
Push — master ( 2f6667...a79c5c )
by Mike
11s
created

MigrationException::duplicateMigrationVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
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 LGPL. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Migrations;
21
22
use \Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface;
23
24
/**
25
 * Class for Migrations specific exceptions
26
 *
27
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28
 * @link        www.doctrine-project.org
29
 * @since       2.0
30
 * @author      Jonathan H. Wage <[email protected]>
31
 */
32
class MigrationException extends \Exception
33
{
34 10
    public static function migrationsNamespaceRequired()
35
    {
36 10
        return new self('Migrations namespace must be configured in order to use Doctrine migrations.', 2);
37
    }
38
39 10
    public static function migrationsDirectoryRequired()
40
    {
41 10
        return new self('Migrations directory must be configured in order to use Doctrine migrations.', 3);
42
    }
43
44 1
    public static function noMigrationsToExecute()
45
    {
46 1
        return new self('Could not find any migrations to execute.', 4);
47
    }
48
49 3
    public static function unknownMigrationVersion($version)
50
    {
51 3
        return new self(sprintf('Could not find migration version %s', $version), 5);
52
    }
53
54
    public static function alreadyAtVersion($version)
55
    {
56
        return new self(sprintf('Database is already at version %s', $version), 6);
57
    }
58
59 1
    public static function duplicateMigrationVersion($version, $class)
60
    {
61 1
        return new self(sprintf('Migration version %s already registered with class %s', $version, $class), 7);
62
    }
63
64 4
    public static function configurationFileAlreadyLoaded()
65
    {
66 4
        return new self(sprintf('Migrations configuration file already loaded'), 8);
67
    }
68
69 8
    public static function configurationIncompatibleWithFinder(
70
        $configurationParameterName,
71
        MigrationFinderInterface $finder
72
    ) {
73 8
        return new self(
74
            sprintf(
75 8
                'Configuration-parameter "%s" cannot be used with finder of type "%s"',
76
                $configurationParameterName,
77
                get_class($finder)
78
            ),
79 8
            9
80
        );
81
    }
82
83 8
    public static function configurationNotValid($msg)
84
    {
85 8
        return new self($msg, 10);
86
    }
87
88
    /**
89
     * @param string $migrationClass
90
     * @param string $migrationNamespace
91
     * @return MigrationException
92
     */
93 1
    public static function migrationClassNotFound($migrationClass, $migrationNamespace)
94
    {
95 1
        return new self(
96
            sprintf(
97 1
                'Migration class "%s" was not found. Is it placed in "%s" namespace?',
98
                $migrationClass,
99
                $migrationNamespace
100
            )
101
        );
102
    }
103
104
    /**
105
     * @param string $migrationClass
106
     * @return MigrationException
107
     */
108 1
    public static function migrationNotConvertibleToSql($migrationClass)
109
    {
110 1
        return new self(
111
            sprintf(
112
                'Migration class "%s" contains a prepared statement.
113
                Unfortunately there is no cross platform way of outputing it as an sql string.
114 1
                Do you want to write a PR for it ?',
115
                $migrationClass
116
            )
117
        );
118
    }
119
}
120