Completed
Push — master ( 824ab5...b7a7bb )
by Arman
16s queued 13s
created

MigrationException::tableAlreadyExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.7.0
13
 */
14
15
namespace Quantum\Exceptions;
16
17
/**
18
 * MigrationException class
19
 *
20
 * @package Quantum
21
 * @category Exceptions
22
 */
23
class MigrationException extends \Exception
24
{
25
26
    /**
27
     * Wrong migration direction message
28
     */
29
    const WRONG_MIGRATION_DIRECTION = 'Migration direction can only be [up] or [down]';
30
    
31
    /**
32
     * Database Driver is not supported message
33
     */
34
    const NON_SUPPORTED_DRIVERER = 'The driver `{%1}`, does not support migrations';
35
    
36
    /**
37
     * Migration action is not supported, possible variants are 'create', 'alter', 'rename', 'drop'
38
     */
39
    const NON_SUPPORTED_ACTION = 'The action `{%1}`, is not supported';
40
    
41
    /**
42
     * Table already exists message
43
     */
44
    const TABLE_ALREADY_EXISTS = 'The table `{%1}` is already exists';
45
    
46
    /**
47
     * Table does not exists message
48
     */
49
    const TABLE_DOES_NOT_EXISTS = 'The table `{%1}` does not exists';
50
    
51
    /**
52
     * Column not available message
53
     */
54
    const COLUMN_NOT_AVAILABLE = 'The column `{%1}` is not available';
55
    
56
    /**
57
     * Method is no defined message
58
     */
59
    const METHOD_NOT_DEFINED = 'The method `{%1}` is not defined';
60
    
61
    /**
62
     * No migrations to migrate
63
     */
64
    const NOTHING_TO_MIGRATE = 'Nothing to migrate';
65
66
    /**
67
     * @return \Quantum\Exceptions\MigrationException
68
     */
69
    public static function wrongDirection(): MigrationException
70
    {
71
        return new static(self::WRONG_MIGRATION_DIRECTION, E_ERROR);
72
    }
73
74
    /**
75
     * @param string $databaseDriver
76
     * @return \Quantum\Exceptions\MigrationException
77
     */
78
    public static function unsupportedDriver(string $databaseDriver): MigrationException
79
    {
80
        return new static(_message(self::NON_SUPPORTED_DRIVERER, $databaseDriver), E_ERROR);
81
    }
82
83
    /**
84
     * @param string $action
85
     * @return MigrationException
86
     */
87
    public static function unsupportedAction(string $action): MigrationException
88
    {
89
        return new static(_message(self::NON_SUPPORTED_ACTION, $action), E_ERROR);
90
    }
91
92
    /**
93
     * @param string $name
94
     * @return \Quantum\Exceptions\MigrationException
95
     */
96
    public static function tableAlreadyExists(string $name): MigrationException
97
    {
98
        return new static(_message(self::TABLE_ALREADY_EXISTS, $name), E_ERROR);
99
    }
100
101
    /**
102
     * @param string $name
103
     * @return \Quantum\Exceptions\MigrationException
104
     */
105
    public static function tableDoesnotExists(string $name): MigrationException
106
    {
107
        return new static(_message(self::TABLE_DOES_NOT_EXISTS, $name), E_ERROR);
108
    }
109
110
    /**
111
     * @param string $name
112
     * @return \Quantum\Exceptions\MigrationException
113
     */
114
    public static function columnNotAvailable(string $name): MigrationException
115
    {
116
        return new static(_message(self::COLUMN_NOT_AVAILABLE, $name), E_ERROR);
117
    }
118
119
    /**
120
     * @param string $name
121
     * @return \Quantum\Exceptions\MigrationException
122
     */
123
    public static function methodNotDefined(string $name): MigrationException
124
    {
125
        return new static(_message(self::METHOD_NOT_DEFINED, $name), E_ERROR);
126
    }
127
128
    /**
129
     * @return \Quantum\Exceptions\MigrationException
130
     */
131
    public static function nothingToMigrate(): MigrationException
132
    {
133
        return new static(self::NOTHING_TO_MIGRATE, E_NOTICE);
134
    }
135
136
}
137