Conditions | 16 |
Paths | 91 |
Total Lines | 74 |
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 |
||
134 | public static function all() |
||
135 | { |
||
136 | $log = array(); |
||
137 | |||
138 | $pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/'; |
||
139 | |||
140 | if (!self::$file) { |
||
141 | $log_file = (!self::$folder) ? self::getFiles() : self::getFolderFiles(); |
||
142 | if(!count($log_file)) { |
||
143 | return []; |
||
144 | } |
||
145 | self::$file = $log_file[0]; |
||
146 | } |
||
147 | |||
148 | if (app('files')->size(self::$file) > self::MAX_FILE_SIZE) return null; |
||
149 | |||
150 | $file = app('files')->get(self::$file); |
||
151 | |||
152 | preg_match_all($pattern, $file, $headings); |
||
153 | |||
154 | if (!is_array($headings)) { |
||
155 | return $log; |
||
156 | } |
||
157 | |||
158 | $log_data = preg_split($pattern, $file); |
||
159 | |||
160 | if ($log_data[0] < 1) { |
||
161 | array_shift($log_data); |
||
162 | } |
||
163 | |||
164 | foreach ($headings as $h) { |
||
165 | for ($i=0, $j = count($h); $i < $j; $i++) { |
||
166 | foreach (self::$log_levels as $level) { |
||
167 | if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) { |
||
168 | |||
169 | 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); |
||
170 | if (!isset($current[4])) continue; |
||
171 | |||
172 | $log[] = array( |
||
173 | 'context' => $current[3], |
||
174 | 'level' => $level, |
||
175 | 'level_class' => self::$levels_classes[$level], |
||
176 | 'level_img' => self::$levels_imgs[$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 | 'level_class' => '', |
||
197 | 'level_img' => '', |
||
198 | 'date' => $key+1, |
||
199 | 'text' => $line, |
||
200 | 'in_file' => null, |
||
201 | 'stack' => '', |
||
202 | ]; |
||
203 | } |
||
204 | } |
||
205 | |||
206 | return array_reverse($log); |
||
207 | } |
||
208 | |||
250 |