| Conditions | 9 |
| Paths | 72 |
| Total Lines | 58 |
| Code Lines | 39 |
| 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 |
||
| 70 | private function getExceptionData($exception) |
||
| 71 | { |
||
| 72 | $data = []; |
||
| 73 | |||
| 74 | $data['host'] = Request::server('HTTP_HOST'); |
||
| 75 | $data['method'] = Request::method(); |
||
| 76 | $data['fullUrl'] = Request::fullUrl(); |
||
| 77 | if (php_sapi_name() === 'cli') { |
||
| 78 | $data['host'] = parse_url(config('app.url'), PHP_URL_HOST); |
||
| 79 | $data['method'] = 'CLI'; |
||
| 80 | } |
||
| 81 | $data['exception'] = $exception->getMessage(); |
||
| 82 | $data['error'] = $exception->getTraceAsString(); |
||
| 83 | $data['line'] = $exception->getLine(); |
||
| 84 | $data['file'] = $exception->getFile(); |
||
| 85 | $data['class'] = get_class($exception); |
||
| 86 | $data['storage'] = array( |
||
| 87 | 'SERVER' => Request::server(), |
||
| 88 | 'GET' => Request::query(), |
||
| 89 | 'POST' => $_POST, |
||
| 90 | 'FILE' => Request::file(), |
||
| 91 | 'OLD' => Request::hasSession() ? Request::old() : [], |
||
| 92 | 'COOKIE' => Request::cookie(), |
||
| 93 | 'SESSION' => Request::hasSession() ? Session::all() : [], |
||
| 94 | 'HEADERS' => Request::header(), |
||
| 95 | ); |
||
| 96 | |||
| 97 | // Remove empty, false and null values |
||
| 98 | $data['storage'] = array_filter($data['storage']); |
||
| 99 | |||
| 100 | // Censor sensitive field values |
||
| 101 | array_walk_recursive($data['storage'], 'self::censorSensitiveFields'); |
||
| 102 | |||
| 103 | $count = $this->config['count']; |
||
| 104 | |||
| 105 | $data['exegutor'] = []; |
||
| 106 | $data['file_lines'] = []; |
||
| 107 | |||
| 108 | $file = new SplFileObject($data['file']); |
||
| 109 | for ($i = -1 * abs($count); $i <= abs($count); $i++) { |
||
| 110 | list($line, $exegutorLine) = $this->getLineInfo($file, $data['line'], $i); |
||
| 111 | if (!$line && !$exegutorLine) { |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | $data['exegutor'][] = $exegutorLine; |
||
| 115 | $data['file_lines'][$data['line'] + $i] = $line; |
||
| 116 | } |
||
| 117 | |||
| 118 | // to make Symfony exception more readable |
||
| 119 | if ($data['class'] == 'Symfony\Component\Debug\Exception\FatalErrorException') { |
||
| 120 | preg_match("~^(.+)' in ~", $data['exception'], $matches); |
||
| 121 | if (isset($matches[1])) { |
||
| 122 | $data['exception'] = $matches[1]; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | return $data; |
||
| 127 | } // end getExceptionData |
||
| 128 | |||
| 166 |
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.