| Conditions | 19 |
| Paths | 18432 |
| Total Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 124 | public function getExceptionArray($exception) |
||
| 125 | { |
||
| 126 | $_message = 'Uknonwn exception object, not instance of \Exception.'; |
||
| 127 | $_file = 'unknown'; |
||
| 128 | $_line = 0; |
||
| 129 | $_trace = []; |
||
| 130 | $_previousException = []; |
||
| 131 | $_exceptionClassName = 'Unknown'; |
||
| 132 | |||
| 133 | if (is_object($exception)) { |
||
| 134 | $_exceptionClassName = get_class($exception); |
||
| 135 | $prev = $exception->getPrevious(); |
||
| 136 | |||
| 137 | if (!empty($prev)) { |
||
| 138 | $_previousException = [ |
||
| 139 | 'message' => $prev->getMessage(), |
||
| 140 | 'file' => $prev->getFile(), |
||
| 141 | 'line' => $prev->getLine(), |
||
| 142 | 'trace' => $this->buildTrace($prev), |
||
| 143 | ]; |
||
| 144 | } |
||
| 145 | |||
| 146 | $_trace = $this->buildTrace($exception); |
||
| 147 | $_message = $exception->getMessage(); |
||
| 148 | $_file = $exception->getFile(); |
||
| 149 | $_line = $exception->getLine(); |
||
| 150 | } elseif (is_string($exception)) { |
||
| 151 | $_message = 'exception string: ' . $exception; |
||
| 152 | } elseif (is_array($exception)) { |
||
| 153 | $_message = isset($exception['message']) ? $exception['message'] : 'exception array dump: ' . print_r($exception, true); |
||
| 154 | $_file = isset($exception['file']) ? $exception['file'] : __FILE__; |
||
| 155 | $_line = isset($exception['line']) ? $exception['line'] : __LINE__; |
||
| 156 | } |
||
| 157 | |||
| 158 | $exceptionName = 'Exception'; |
||
| 159 | |||
| 160 | if ($exception instanceof Exception) { |
||
| 161 | $exceptionName = $exception->getName(); |
||
| 162 | } elseif ($exception instanceof ErrorException) { |
||
| 163 | $exceptionName = $exception->getName(); |
||
| 164 | } |
||
| 165 | |||
| 166 | return [ |
||
| 167 | 'message' => $_message, |
||
| 168 | 'file' => $_file, |
||
| 169 | 'line' => $_line, |
||
| 170 | 'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null, |
||
| 171 | 'serverName' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null, |
||
| 172 | 'date' => date('d.m.Y H:i'), |
||
| 173 | 'trace' => $_trace, |
||
| 174 | 'previousException' => $_previousException, |
||
| 175 | 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null, |
||
| 176 | 'get' => isset($_GET) ? ArrayHelper::coverSensitiveValues($_GET, $this->sensitiveKeys) : [], |
||
| 177 | 'post' => isset($_POST) ? ArrayHelper::coverSensitiveValues($_POST, $this->sensitiveKeys) : [], |
||
| 178 | 'bodyParams' => Yii::$app instanceof Application ? ArrayHelper::coverSensitiveValues(Yii::$app->request->bodyParams) : [], |
||
| 179 | 'session' => isset($_SESSION) ? ArrayHelper::coverSensitiveValues($_SESSION, $this->sensitiveKeys) : [], |
||
| 180 | 'server' => isset($_SERVER) ? ArrayHelper::coverSensitiveValues($_SERVER, $this->sensitiveKeys) : [], |
||
| 181 | // since 1.0.20 |
||
| 182 | 'yii_debug' => YII_DEBUG, |
||
| 183 | 'yii_env' => YII_ENV, |
||
| 184 | 'status_code' => $exception instanceof HttpException ? $exception->statusCode : 500, |
||
| 185 | 'exception_name' => $exceptionName, |
||
| 186 | 'exception_class_name' => $_exceptionClassName, |
||
| 187 | 'php_version' => phpversion(), |
||
| 188 | 'luya_version' => Boot::VERSION, |
||
| 189 | ]; |
||
| 190 | } |
||
| 191 | |||
| 266 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.