1 | <?php |
||||
2 | /** |
||||
3 | * This file is part of the O2System Framework package. |
||||
4 | * |
||||
5 | * For the full copyright and license information, please view the LICENSE |
||||
6 | * file that was distributed with this source code. |
||||
7 | * |
||||
8 | * @author Steeve Andrian Salim |
||||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
10 | */ |
||||
11 | |||||
12 | // ------------------------------------------------------------------------ |
||||
13 | |||||
14 | namespace O2System\Spl\Exceptions; |
||||
15 | |||||
16 | // ------------------------------------------------------------------------ |
||||
17 | |||||
18 | use O2System\Spl\Exceptions\Abstracts\AbstractException; |
||||
19 | |||||
20 | /** |
||||
21 | * Class ErrorException |
||||
22 | * |
||||
23 | * ErrorException is the wrapper class of the predefined exceptions PHP Error class. |
||||
24 | * |
||||
25 | * @see http://php.net/manual/en/class.error.php |
||||
26 | * |
||||
27 | * @package O2System\Spl\Exceptions\Logic |
||||
28 | */ |
||||
29 | class ErrorException extends AbstractException |
||||
30 | { |
||||
31 | /** |
||||
32 | * ErrorException::$severity |
||||
33 | * |
||||
34 | * The severity of the error exception. |
||||
35 | * |
||||
36 | * @var int |
||||
37 | */ |
||||
38 | protected $severity; |
||||
39 | |||||
40 | // ------------------------------------------------------------------------ |
||||
41 | |||||
42 | /** |
||||
43 | * ErrorException::__construct |
||||
44 | * |
||||
45 | * @param string $message |
||||
46 | * @param array|int $severity |
||||
47 | * @param string $filename |
||||
48 | * @param int $line |
||||
49 | * @param \Exception|null $previous |
||||
50 | */ |
||||
51 | public function __construct( |
||||
52 | $message = '', |
||||
53 | $severity = 1, |
||||
54 | $filename = '', |
||||
55 | $line = 0, |
||||
56 | $context = [] |
||||
57 | ) { |
||||
58 | $this->severity = $severity; |
||||
0 ignored issues
–
show
|
|||||
59 | $this->file = $filename; |
||||
60 | $this->line = $line; |
||||
61 | |||||
62 | if (class_exists('O2System\Kernel', false)) { |
||||
63 | if (is_array($context)) { |
||||
64 | $message = language()->getLine($message, $context); |
||||
0 ignored issues
–
show
The function
language was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
65 | } else { |
||||
66 | $message = language()->getLine($message); |
||||
67 | } |
||||
68 | } |
||||
69 | |||||
70 | parent::__construct($message, 0, []); |
||||
71 | } |
||||
72 | |||||
73 | // ------------------------------------------------------------------------ |
||||
74 | |||||
75 | /** |
||||
76 | * ErrorException::getSeverity |
||||
77 | * |
||||
78 | * Gets the exception severity. |
||||
79 | * |
||||
80 | * @return int |
||||
81 | */ |
||||
82 | public function getSeverity() |
||||
83 | { |
||||
84 | return $this->severity; |
||||
85 | } |
||||
86 | |||||
87 | // ------------------------------------------------------------------------ |
||||
88 | |||||
89 | /** |
||||
90 | * ErrorException::getStringSeverity |
||||
91 | * |
||||
92 | * Gets the exception severity string. |
||||
93 | * |
||||
94 | * @return string |
||||
95 | */ |
||||
96 | public function getStringSeverity() |
||||
97 | { |
||||
98 | switch ($this->severity) { |
||||
99 | case E_ERROR: // 1 // |
||||
100 | return 'E_ERROR'; |
||||
101 | case E_WARNING: // 2 // |
||||
102 | return 'E_WARNING'; |
||||
103 | case E_PARSE: // 4 // |
||||
104 | return 'E_PARSE'; |
||||
105 | case E_NOTICE: // 8 // |
||||
106 | return 'E_NOTICE'; |
||||
107 | case E_CORE_ERROR: // 16 // |
||||
108 | return 'E_CORE_ERROR'; |
||||
109 | case E_CORE_WARNING: // 32 // |
||||
110 | return 'E_CORE_WARNING'; |
||||
111 | case E_COMPILE_ERROR: // 64 // |
||||
112 | return 'E_COMPILE_ERROR'; |
||||
113 | case E_COMPILE_WARNING: // 128 // |
||||
114 | return 'E_COMPILE_WARNING'; |
||||
115 | case E_USER_ERROR: // 256 // |
||||
116 | return 'E_USER_ERROR'; |
||||
117 | case E_USER_WARNING: // 512 // |
||||
118 | return 'E_USER_WARNING'; |
||||
119 | case E_USER_NOTICE: // 1024 // |
||||
120 | return 'E_USER_NOTICE'; |
||||
121 | case E_STRICT: // 2048 // |
||||
122 | return 'E_STRICT'; |
||||
123 | case E_RECOVERABLE_ERROR: // 4096 // |
||||
124 | return 'E_RECOVERABLE_ERROR'; |
||||
125 | case E_DEPRECATED: // 8192 // |
||||
126 | return 'E_DEPRECATED'; |
||||
127 | case E_USER_DEPRECATED: // 16384 // |
||||
128 | return 'E_USER_DEPRECATED'; |
||||
129 | } |
||||
130 | |||||
131 | return ''; |
||||
132 | } |
||||
133 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.