Conditions | 13 |
Paths | 33 |
Total Lines | 53 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 12 | ||
Bugs | 0 | Features | 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 |
||
108 | public static function all() |
||
109 | { |
||
110 | $log = array(); |
||
111 | |||
112 | $pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/'; |
||
113 | |||
114 | if (!self::$file) { |
||
115 | $log_file = self::getFiles(); |
||
116 | if(!count($log_file)) { |
||
117 | return []; |
||
118 | } |
||
119 | self::$file = $log_file[0]; |
||
120 | } |
||
121 | |||
122 | if (app('files')->size(self::$file) > self::MAX_FILE_SIZE) return null; |
||
123 | |||
124 | $file = app('files')->get(self::$file); |
||
125 | |||
126 | preg_match_all($pattern, $file, $headings); |
||
127 | |||
128 | if (!is_array($headings)) return $log; |
||
129 | |||
130 | $log_data = preg_split($pattern, $file); |
||
131 | |||
132 | if ($log_data[0] < 1) { |
||
133 | array_shift($log_data); |
||
134 | } |
||
135 | |||
136 | foreach ($headings as $h) { |
||
137 | for ($i=0, $j = count($h); $i < $j; $i++) { |
||
138 | foreach (self::$log_levels as $level) { |
||
139 | if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) { |
||
140 | |||
141 | preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?)\](?:.*?(\w+)\.|.*?)' . $level . ': (.*?)( in .*?:[0-9]+)?$/i', $h[$i], $current); |
||
142 | if (!isset($current[4])) continue; |
||
143 | |||
144 | $log[] = array( |
||
145 | 'context' => $current[3], |
||
146 | 'level' => $level, |
||
147 | 'level_class' => self::$levels_classes[$level], |
||
148 | 'level_img' => self::$levels_imgs[$level], |
||
149 | 'date' => $current[1], |
||
150 | 'text' => $current[4], |
||
151 | 'in_file' => isset($current[5]) ? $current[5] : null, |
||
152 | 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) |
||
153 | ); |
||
154 | } |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | |||
159 | return array_reverse($log); |
||
160 | } |
||
161 | |||
179 |