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 |
||
107 | public function all() |
||
108 | { |
||
109 | $log = array(); |
||
110 | |||
111 | $pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/'; |
||
112 | |||
113 | if (!$this->file) { |
||
114 | $log_file = (!$this->folder) ? $this->getFiles() : $this->getFolderFiles(); |
||
115 | if (!count($log_file)) { |
||
116 | return []; |
||
117 | } |
||
118 | $this->file = $log_file[0]; |
||
119 | } |
||
120 | |||
121 | if (app('files')->size($this->file) > self::MAX_FILE_SIZE) return null; |
||
122 | |||
123 | $file = app('files')->get($this->file); |
||
124 | |||
125 | preg_match_all($pattern, $file, $headings); |
||
126 | |||
127 | if (!is_array($headings)) { |
||
128 | return $log; |
||
129 | } |
||
130 | |||
131 | $log_data = preg_split($pattern, $file); |
||
132 | |||
133 | if ($log_data[0] < 1) { |
||
134 | array_shift($log_data); |
||
135 | } |
||
136 | |||
137 | foreach ($headings as $h) { |
||
138 | for ($i = 0, $j = count($h); $i < $j; $i++) { |
||
139 | foreach ($this->level->all() as $level) { |
||
140 | if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) { |
||
141 | |||
142 | 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); |
||
143 | if (!isset($current[4])) continue; |
||
144 | |||
145 | $log[] = array( |
||
146 | 'context' => $current[3], |
||
147 | 'level' => $level, |
||
148 | 'level_class' => $this->level->cssClass($level), |
||
149 | 'level_img' => $this->level->img($level), |
||
150 | 'date' => $current[1], |
||
151 | 'text' => $current[4], |
||
152 | 'in_file' => isset($current[5]) ? $current[5] : null, |
||
153 | 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) |
||
154 | ); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | if (empty($log)) { |
||
161 | |||
162 | $lines = explode(PHP_EOL, $file); |
||
163 | $log = []; |
||
164 | |||
165 | foreach ($lines as $key => $line) { |
||
166 | $log[] = [ |
||
167 | 'context' => '', |
||
168 | 'level' => '', |
||
169 | 'level_class' => '', |
||
170 | 'level_img' => '', |
||
171 | 'date' => $key + 1, |
||
172 | 'text' => $line, |
||
173 | 'in_file' => null, |
||
174 | 'stack' => '', |
||
175 | ]; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | return array_reverse($log); |
||
180 | } |
||
181 | |||
224 |