| Conditions | 12 |
| Paths | 33 |
| Total Lines | 55 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 15 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 85 | public static function all() |
||
| 86 | { |
||
| 87 | $log = array(); |
||
| 88 | |||
| 89 | $log_levels = self::getLogLevels(); |
||
| 90 | |||
| 91 | $pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/'; |
||
| 92 | |||
| 93 | if (!self::$file) { |
||
| 94 | $log_file = self::getFiles(); |
||
| 95 | if(!count($log_file)) { |
||
| 96 | return []; |
||
| 97 | } |
||
| 98 | self::$file = $log_file[0]; |
||
| 99 | } |
||
| 100 | |||
| 101 | if (File::size(self::$file) > self::MAX_FILE_SIZE) return null; |
||
| 102 | |||
| 103 | $file = File::get(self::$file); |
||
| 104 | |||
| 105 | preg_match_all($pattern, $file, $headings); |
||
| 106 | |||
| 107 | if (!is_array($headings)) return $log; |
||
| 108 | |||
| 109 | $log_data = preg_split($pattern, $file); |
||
| 110 | |||
| 111 | if ($log_data[0] < 1) { |
||
| 112 | array_shift($log_data); |
||
| 113 | } |
||
| 114 | |||
| 115 | foreach ($headings as $h) { |
||
| 116 | for ($i=0, $j = count($h); $i < $j; $i++) { |
||
| 117 | foreach ($log_levels as $level_key => $level_value) { |
||
| 118 | if (strpos(strtolower($h[$i]), '.' . $level_value)) { |
||
| 119 | |||
| 120 | preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current); |
||
| 121 | |||
| 122 | if (!isset($current[2])) continue; |
||
| 123 | |||
| 124 | $log[] = array( |
||
| 125 | 'level' => $level_value, |
||
| 126 | 'level_class' => self::$levels_classes[$level_value], |
||
| 127 | 'level_img' => self::$levels_imgs[$level_value], |
||
| 128 | 'date' => $current[1], |
||
| 129 | 'text' => $current[2], |
||
| 130 | 'in_file' => isset($current[3]) ? $current[3] : null, |
||
| 131 | 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return array_reverse($log); |
||
| 139 | } |
||
| 140 | |||
| 200 |