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