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