These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @link http://www.yiiframework.com/ |
||
4 | * @copyright Copyright (c) 2008 Yii Software LLC |
||
5 | * @license http://www.yiiframework.com/license/ |
||
6 | */ |
||
7 | |||
8 | namespace yii\console; |
||
9 | |||
10 | /** |
||
11 | * This class provides constants for defining console command exit codes. |
||
12 | * |
||
13 | * The exit codes follow the codes defined in the [FreeBSD sysexits(3)](http://man.openbsd.org/sysexits) manual page. |
||
14 | * |
||
15 | * These constants can be used in console controllers for example like this: |
||
16 | * |
||
17 | * ```php |
||
18 | * public function actionIndex() |
||
19 | * { |
||
20 | * if (!$this->isAllowedToPerformAction()) { |
||
21 | * $this->stderr('Error: ' . ExitCode::getReason(ExitCode::NOPERM)); |
||
22 | * return ExitCode::NOPERM; |
||
23 | * } |
||
24 | * |
||
25 | * // do something |
||
26 | * |
||
27 | * return ExitCode::OK; |
||
28 | * } |
||
29 | * ``` |
||
30 | * |
||
31 | * @author Tom Worster <[email protected]> |
||
32 | * @author Alexander Makarov <[email protected]> |
||
33 | * @see http://man.openbsd.org/sysexits |
||
34 | * @since 2.0.13 |
||
35 | */ |
||
36 | class ExitCode |
||
37 | { |
||
38 | /** |
||
39 | * The command completed successfully. |
||
40 | */ |
||
41 | const OK = 0; |
||
42 | /** |
||
43 | * The command exited with an error code that says nothing about the error. |
||
44 | */ |
||
45 | const UNSPECIFIED_ERROR = 1; |
||
46 | /** |
||
47 | * The command was used incorrectly, e.g., with the wrong number of |
||
48 | * arguments, a bad flag, a bad syntax in a parameter, or whatever. |
||
49 | */ |
||
50 | const USAGE = 64; |
||
51 | /** |
||
52 | * The input data was incorrect in some way. This should only be used for |
||
53 | * user's data and not system files. |
||
54 | */ |
||
55 | const DATAERR = 65; |
||
56 | /** |
||
57 | * An input file (not a system file) did not exist or was not readable. |
||
58 | * This could also include errors like ``No message'' to a mailer (if it |
||
59 | * cared to catch it). |
||
60 | */ |
||
61 | const NOINPUT = 66; |
||
62 | /** |
||
63 | * The user specified did not exist. This might be used for mail addresses |
||
64 | * or remote logins. |
||
65 | */ |
||
66 | const NOUSER = 67; |
||
67 | /** |
||
68 | * The host specified did not exist. This is used in mail addresses or |
||
69 | * network requests. |
||
70 | */ |
||
71 | const NOHOST = 68; |
||
72 | /** |
||
73 | * A service is unavailable. This can occur if a support program or file |
||
74 | * does not exist. This can also be used as a catchall message when |
||
75 | * something you wanted to do does not work, but you do not know why. |
||
76 | */ |
||
77 | const UNAVAILABLE = 69; |
||
78 | /** |
||
79 | * An internal software error has been detected. This should be limited to |
||
80 | * non-operating system related errors as possible. |
||
81 | */ |
||
82 | const SOFTWARE = 70; |
||
83 | /** |
||
84 | * An operating system error has been detected. This is intended to be |
||
85 | * used for such things as ``cannot fork'', ``cannot create pipe'', or the |
||
86 | * like. It includes things like getuid returning a user that does not |
||
87 | * exist in the passwd file. |
||
88 | */ |
||
89 | const OSERR = 71; |
||
90 | /** |
||
91 | * Some system file (e.g., /etc/passwd, /var/run/utx.active, etc.) does not |
||
92 | * exist, cannot be opened, or has some sort of error (e.g., syntax error). |
||
93 | */ |
||
94 | const OSFILE = 72; |
||
95 | /** |
||
96 | * A (user specified) output file cannot be created. |
||
97 | */ |
||
98 | const CANTCREAT = 73; |
||
99 | /** |
||
100 | * An error occurred while doing I/O on some file. |
||
101 | */ |
||
102 | const IOERR = 74; |
||
103 | /** |
||
104 | * Temporary failure, indicating something that is not really an error. In |
||
105 | * sendmail, this means that a mailer (e.g.) could not create a connection, |
||
106 | * and the request should be reattempted later. |
||
107 | */ |
||
108 | const TEMPFAIL = 75; |
||
109 | /** |
||
110 | * The remote system returned something that was ``not possible'' during a |
||
111 | * protocol exchange. |
||
112 | */ |
||
113 | const PROTOCOL = 76; |
||
114 | /** |
||
115 | * You did not have sufficient permission to perform the operation. This |
||
116 | * is not intended for file system problems, which should use NOINPUT or |
||
117 | * CANTCREAT, but rather for higher level permissions. |
||
118 | */ |
||
119 | const NOPERM = 77; |
||
120 | /** |
||
121 | * Something was found in an unconfigured or misconfigured state. |
||
122 | */ |
||
123 | const CONFIG = 78; |
||
124 | |||
125 | /** |
||
126 | * @var array a map of reason descriptions for exit codes. |
||
127 | */ |
||
128 | public static $reasons = [ |
||
129 | self::OK => 'Success', |
||
130 | self::UNSPECIFIED_ERROR => 'Unspecified error', |
||
131 | self::USAGE => 'Incorrect usage, argument or option error', |
||
132 | self::DATAERR => 'Error in input data', |
||
133 | self::NOINPUT => 'Input file not found or unreadable', |
||
134 | self::NOUSER => 'User not found', |
||
135 | self::NOHOST => 'Host not found', |
||
136 | self::UNAVAILABLE => 'A requied service is unavailable', |
||
137 | self::SOFTWARE => 'Internal error', |
||
138 | self::OSERR => 'Error making system call or using OS service', |
||
139 | self::OSFILE => 'Error accessing system file', |
||
140 | self::CANTCREAT => 'Cannot create output file', |
||
141 | self::IOERR => 'I/O error', |
||
142 | self::TEMPFAIL => 'Temporary failure', |
||
143 | self::PROTOCOL => 'Unexpected remote service behavior', |
||
144 | self::NOPERM => 'Insufficient permissions', |
||
145 | self::CONFIG => 'Configuration error', |
||
146 | ]; |
||
147 | |||
148 | /** |
||
149 | * Returns a short reason text for the given exit code. |
||
150 | * |
||
151 | * This method uses [[$reasons]] to determine the reason for an exit code. |
||
152 | * @param int $exitCode one of the constants defined in this class. |
||
153 | * @return string the reason text, or `"Unknown exit code"` if the code is not listed in [[$reasons]]. |
||
154 | */ |
||
155 | public static function getReason($exitCode) |
||
156 | { |
||
157 | return isset($exReasons[$exitCode]) ? $exReasons[$exitCode] : 'Unknown exit code'; |
||
0 ignored issues
–
show
|
|||
158 | } |
||
159 | } |
||
160 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.