| Conditions | 16 |
| Paths | 91 |
| Total Lines | 72 |
| 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 all() |
||
| 121 | { |
||
| 122 | $log = array(); |
||
| 123 | |||
| 124 | if (!$this->file) { |
||
| 125 | $log_file = (!$this->folder) ? $this->getFiles() : $this->getFolderFiles(); |
||
| 126 | if (!count($log_file)) { |
||
| 127 | return []; |
||
| 128 | } |
||
| 129 | $this->file = $log_file[0]; |
||
| 130 | } |
||
| 131 | |||
| 132 | if (app('files')->size($this->file) > self::MAX_FILE_SIZE) return null; |
||
| 133 | |||
| 134 | $file = app('files')->get($this->file); |
||
| 135 | |||
| 136 | preg_match_all($this->pattern->getPattern('logs'), $file, $headings); |
||
| 137 | |||
| 138 | if (!is_array($headings)) { |
||
| 139 | return $log; |
||
| 140 | } |
||
| 141 | |||
| 142 | $log_data = preg_split($this->pattern->getPattern('logs'), $file); |
||
| 143 | |||
| 144 | if ($log_data[0] < 1) { |
||
| 145 | array_shift($log_data); |
||
| 146 | } |
||
| 147 | |||
| 148 | foreach ($headings as $h) { |
||
| 149 | for ($i = 0, $j = count($h); $i < $j; $i++) { |
||
| 150 | foreach ($this->level->all() as $level) { |
||
| 151 | if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) { |
||
| 152 | |||
| 153 | preg_match($this->pattern->getPattern('current_log',0) . $level . $this->pattern->getPattern('current_log',1), $h[$i], $current); |
||
| 154 | if (!isset($current[4])) continue; |
||
| 155 | |||
| 156 | $log[] = array( |
||
| 157 | 'context' => $current[3], |
||
| 158 | 'level' => $level, |
||
| 159 | 'level_class' => $this->level->cssClass($level), |
||
| 160 | 'level_img' => $this->level->img($level), |
||
| 161 | 'date' => $current[1], |
||
| 162 | 'text' => $current[4], |
||
| 163 | 'in_file' => isset($current[5]) ? $current[5] : null, |
||
| 164 | 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | if (empty($log)) { |
||
| 172 | |||
| 173 | $lines = explode(PHP_EOL, $file); |
||
| 174 | $log = []; |
||
| 175 | |||
| 176 | foreach ($lines as $key => $line) { |
||
| 177 | $log[] = [ |
||
| 178 | 'context' => '', |
||
| 179 | 'level' => '', |
||
| 180 | 'level_class' => '', |
||
| 181 | 'level_img' => '', |
||
| 182 | 'date' => $key + 1, |
||
| 183 | 'text' => $line, |
||
| 184 | 'in_file' => null, |
||
| 185 | 'stack' => '', |
||
| 186 | ]; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | return array_reverse($log); |
||
| 191 | } |
||
| 192 | |||
| 243 |