| Conditions | 15 |
| Paths | 1536 |
| Total Lines | 50 |
| 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 |
||
| 120 | public function getExceptionArray($exception) |
||
| 121 | { |
||
| 122 | $_message = 'Uknonwn exception object, not instance of \Exception.'; |
||
| 123 | $_file = 'unknown'; |
||
| 124 | $_line = 0; |
||
| 125 | $_trace = []; |
||
| 126 | $_previousException = []; |
||
| 127 | |||
| 128 | if (is_object($exception)) { |
||
| 129 | $prev = $exception->getPrevious(); |
||
| 130 | |||
| 131 | if (!empty($prev)) { |
||
| 132 | $_previousException = [ |
||
| 133 | 'message' => $prev->getMessage(), |
||
| 134 | 'file' => $prev->getFile(), |
||
| 135 | 'line' => $prev->getLine(), |
||
| 136 | 'trace' => $this->buildTrace($prev), |
||
| 137 | ]; |
||
| 138 | } |
||
| 139 | |||
| 140 | $_trace = $this->buildTrace($exception); |
||
| 141 | $_message = $exception->getMessage(); |
||
| 142 | $_file = $exception->getFile(); |
||
| 143 | $_line = $exception->getLine(); |
||
| 144 | } elseif (is_string($exception)) { |
||
| 145 | $_message = 'exception string: ' . $exception; |
||
| 146 | } elseif (is_array($exception)) { |
||
| 147 | $_message = isset($exception['message']) ? $exception['message'] : 'exception array dump: ' . print_r($exception, true); |
||
| 148 | $_file = isset($exception['file']) ? $exception['file'] : __FILE__; |
||
| 149 | $_line = isset($exception['line']) ? $exception['line'] : __LINE__; |
||
| 150 | } |
||
| 151 | |||
| 152 | return [ |
||
| 153 | 'message' => $_message, |
||
| 154 | 'file' => $_file, |
||
| 155 | 'line' => $_line, |
||
| 156 | 'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null, |
||
| 157 | 'serverName' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null, |
||
| 158 | 'date' => date('d.m.Y H:i'), |
||
| 159 | 'trace' => $_trace, |
||
| 160 | 'previousException' => $_previousException, |
||
| 161 | 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null, |
||
| 162 | 'get' => isset($_GET) ? ArrayHelper::coverSensitiveValues($_GET, $this->sensitiveKeys) : [], |
||
| 163 | 'post' => isset($_POST) ? ArrayHelper::coverSensitiveValues($_POST, $this->sensitiveKeys) : [], |
||
| 164 | 'session' => isset($_SESSION) ? ArrayHelper::coverSensitiveValues($_SESSION, $this->sensitiveKeys) : [], |
||
| 165 | 'server' => isset($_SERVER) ? ArrayHelper::coverSensitiveValues($_SERVER, $this->sensitiveKeys) : [], |
||
| 166 | 'profiling' => Yii::getLogger()->profiling, |
||
| 167 | 'logger' => Yii::getLogger()->messages, |
||
| 168 | ]; |
||
| 169 | } |
||
| 170 | |||
| 192 |