Completed
Push — master ( f84b1b...3c5fbc )
by Arman
14s
created

ModelException::missingForeignKeyValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Quantum PHP Framework
7
 *
8
 * An open source software development framework for PHP
9
 *
10
 * @package Quantum
11
 * @author Arman Ag. <[email protected]>
12
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
13
 * @link http://quantum.softberg.org/
14
 * @since 3.0.0
15
 */
16
17
namespace Quantum\Model\Exceptions;
18
19
use Quantum\Model\Enums\ExceptionMessages;
20
use Quantum\App\Exceptions\BaseException;
21
22
/**
23
 * Class ModelException
24
 * @package Quantum\Model
25
 */
26
class ModelException extends BaseException
27
{
28
    /**
29
     * @param string $name
30
     * @return ModelException
31
     */
32
    public static function inappropriateProperty(string $name): self
33
    {
34
        return new self(
35
            _message(ExceptionMessages::INAPPROPRIATE_MODEL_PROPERTY, $name),
36
            E_WARNING
37
        );
38
    }
39
40
    /**
41
     * @param string $modelName
42
     * @param string $tableName
43
     * @return ModelException
44
     */
45
    public static function wrongRelation(string $modelName, string $tableName): self
46
    {
47
        return new self(
48
            _message(ExceptionMessages::WRONG_RELATION, [$modelName, $tableName]),
49
            E_ERROR
50
        );
51
    }
52
53
    /**
54
     * @param string $modelName
55
     * @param string $relatedModelName
56
     * @return ModelException
57
     */
58
    public static function relationTypeMissing(string $modelName, string $relatedModelName): self
59
    {
60
        return new self(
61
            _message(ExceptionMessages::RELATION_TYPE_MISSING, [$modelName, $relatedModelName]),
62
            E_ERROR
63
        );
64
    }
65
66
    /**
67
     * @param string $modelName
68
     * @param string $relatedModelName
69
     * @return ModelException
70
     */
71
    public static function missingRelationKeys(string $modelName, string $relatedModelName): self
72
    {
73
        return new self(
74
            _message(ExceptionMessages::MISSING_RELATION_KEYS, [$modelName, $relatedModelName]),
75
            E_ERROR
76
        );
77
    }
78
79
    /**
80
     * @param string $modelName
81
     * @param string $foreignKey
82
     * @return ModelException
83
     */
84
    public static function missingForeignKeyValue(string $modelName, string $foreignKey): self
85
    {
86
        return new self(
87
            _message(ExceptionMessages::MISSING_FOREIGN_KEY, [$foreignKey, $modelName]),
88
            E_ERROR
89
        );
90
    }
91
92
    /**
93
     * @param string $relationType
94
     * @return ModelException
95
     */
96
    public static function unsupportedRelationType(string $relationType): self
97
    {
98
        return new self(
99
            _message(ExceptionMessages::UNSUPPORTED_RELATION, [$relationType]),
100
            E_ERROR
101
        );
102
    }
103
104
    /**
105
     * @return ModelException
106
     */
107
    public static function ormIsNotSet(): self
108
    {
109
        return new self(
110
            ExceptionMessages::ORM_IS_NOT_SET,
111
            E_ERROR
112
        );
113
    }
114
}
115