Passed
Pull Request — master (#43)
by Arman
03:54
created

ModelException::undefinedMethod()   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
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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.5.0
13
 */
14
15
namespace Quantum\Exceptions;
16
17
/**
18
 * Class ModelException
19
 * @package Quantum\Exceptions
20
 */
21
class ModelException extends \Exception
22
{
23
    /**
24
     * Model not found message
25
     */
26
    const MODEL_NOT_FOUND = 'Model `{%1}` not found';
27
28
    /**
29
     * Model not instance of QtModel
30
     */
31
    const NOT_INSTANCE_OF_MODEL = 'Model `{%1}` is not instance of `{%2}`';
32
33
    /**
34
     * Model does not have table property defined
35
     */
36
    const MODEL_WITHOUT_TABLE_DEFINED = 'Model `{%1}` does not have $table property defined';
37
38
    /**
39
     * Undefined model method
40
     */
41
    const UNDEFINED_MODEL_METHOD = 'Model method `{%1}` is not defined';
42
43
    /**
44
     * Inappropriate property message
45
     */
46
    const INAPPROPRIATE_PROPERTY = 'Inappropriate property `{%1}` for fillable object';
47
48
    /**
49
     * @param string $name
50
     * @return \Quantum\Exceptions\ModelException
51
     */
52
    public static function notFound(string $name): ModelException
53
    {
54
        return new static(_message(self::MODEL_NOT_FOUND, $name), E_ERROR);
55
    }
56
57
    /**
58
     * @param array $names
59
     * @return \Quantum\Exceptions\ModelException
60
     */
61
    public static function notModelInstance(array $names): ModelException
62
    {
63
        return new static(_message(self::NOT_INSTANCE_OF_MODEL, $names), E_WARNING);
64
    }
65
66
    /**
67
     * @param string|null $name
68
     * @return \Quantum\Exceptions\ModelException
69
     */
70
    public static function noTableDefined(?string $name): ModelException
71
    {
72
        return new static(_message(self::MODEL_WITHOUT_TABLE_DEFINED, $name), E_WARNING);
73
    }
74
75
    /**
76
     * @param string $name
77
     * @return \Quantum\Exceptions\ModelException
78
     */
79
    public static function undefinedMethod(string $name): ModelException
80
    {
81
        return new static(_message(self::UNDEFINED_MODEL_METHOD, $name), E_WARNING);
82
    }
83
84
    /**
85
     * @param string $name
86
     * @return \Quantum\Exceptions\ModelException
87
     */
88
    public static function inappropriateProperty(string $name): ModelException
89
    {
90
        return new static(_message(self::INAPPROPRIATE_PROPERTY, $name), E_WARNING);
91
    }
92
}
93