Passed
Pull Request — master (#65)
by Arman
03:48
created

MigrationException::unsupportedAction()   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
    const WRONG_MIGRATION_DIRECTION = 'Migration direction can only be [up] or [down]';
27
    const NON_SUPPORTED_DRIVERER = 'The driver `{%1}`, does not support migrations';
28
    const NON_SUPPORTED_ACTION = 'The action `{%1}`, is not supported';
29
    const TABLE_ALREADY_EXISTS = 'The table `{%1}` is already exists';
30
    const TABLE_DOES_NOT_EXISTS = 'The table `{%1}` does not exists';
31
    const COLUMN_NOT_AVAILABLE = 'The column `{%1}` is not available';
32
    const METHOD_NOT_DEFINED = 'The method `{%1}` is not defined';
33
    const NOTHING_TO_MIGRATE = 'Nothing to migrate';
34
35
    /**
36
     * @return \Quantum\Exceptions\MigrationException
37
     */
38
    public static function wrongDirection(): MigrationException
39
    {
40
        return new static(self::WRONG_MIGRATION_DIRECTION, E_ERROR);
41
    }
42
43
    /**
44
     * @param string $databaseDriver
45
     * @return \Quantum\Exceptions\MigrationException
46
     */
47
    public static function unsupportedDriver(string $databaseDriver): MigrationException
48
    {
49
        return new static(_message(self::NON_SUPPORTED_DRIVERER, $databaseDriver), E_ERROR);
50
    }
51
52
    /**
53
     * @param string $action
54
     * @return MigrationException
55
     */
56
    public static function unsupportedAction(string $action): MigrationException
57
    {
58
        return new static(_message(self::NON_SUPPORTED_ACTION, $action), E_ERROR);
59
    }
60
61
    /**
62
     * @param string $name
63
     * @return \Quantum\Exceptions\MigrationException
64
     */
65
    public static function tableAlreadyExists(string $name): MigrationException
66
    {
67
        return new static(_message(self::TABLE_ALREADY_EXISTS, $name), E_ERROR);
68
    }
69
70
    /**
71
     * @param string $name
72
     * @return \Quantum\Exceptions\MigrationException
73
     */
74
    public static function tableDoesnotExists(string $name): MigrationException
75
    {
76
        return new static(_message(self::TABLE_DOES_NOT_EXISTS, $name), E_ERROR);
77
    }
78
79
    /**
80
     * @param string $name
81
     * @return \Quantum\Exceptions\MigrationException
82
     */
83
    public static function columnNotAvailable(string $name): MigrationException
84
    {
85
        return new static(_message(self::COLUMN_NOT_AVAILABLE, $name), E_ERROR);
86
    }
87
88
    /**
89
     * @param string $name
90
     * @return \Quantum\Exceptions\MigrationException
91
     */
92
    public static function methodNotDefined(string $name): MigrationException
93
    {
94
        return new static(_message(self::METHOD_NOT_DEFINED, $name), E_ERROR);
95
    }
96
97
    /**
98
     * @return \Quantum\Exceptions\MigrationException
99
     */
100
    public static function nothingToMigrate(): MigrationException
101
    {
102
        return new static(self::NOTHING_TO_MIGRATE, E_NOTICE);
103
    }
104
105
}
106