Conditions | 16 |
Paths | 91 |
Total Lines | 77 |
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 |
||
127 | public function all() |
||
128 | { |
||
129 | $log = array(); |
||
130 | |||
131 | if (!$this->file) { |
||
132 | $log_file = (!$this->folder) ? $this->getFiles() : $this->getFolderFiles(); |
||
133 | if (!count($log_file)) { |
||
134 | return []; |
||
135 | } |
||
136 | $this->file = $log_file[0]; |
||
137 | } |
||
138 | |||
139 | if (app('files')->size($this->file) > self::MAX_FILE_SIZE) { |
||
140 | return null; |
||
141 | } |
||
142 | |||
143 | $file = app('files')->get($this->file); |
||
144 | |||
145 | preg_match_all($this->pattern->getPattern('logs'), $file, $headings); |
||
146 | |||
147 | if (!is_array($headings)) { |
||
148 | return $log; |
||
149 | } |
||
150 | |||
151 | $log_data = preg_split($this->pattern->getPattern('logs'), $file); |
||
152 | |||
153 | if ($log_data[0] < 1) { |
||
154 | array_shift($log_data); |
||
155 | } |
||
156 | |||
157 | foreach ($headings as $h) { |
||
158 | for ($i = 0, $j = count($h); $i < $j; $i++) { |
||
159 | foreach ($this->level->all() as $level) { |
||
160 | if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) { |
||
161 | |||
162 | preg_match($this->pattern->getPattern('current_log', |
||
163 | 0) . $level . $this->pattern->getPattern('current_log', 1), $h[$i], $current); |
||
164 | if (!isset($current[4])) { |
||
165 | continue; |
||
166 | } |
||
167 | |||
168 | $log[] = array( |
||
169 | 'context' => $current[3], |
||
170 | 'level' => $level, |
||
171 | 'level_class' => $this->level->cssClass($level), |
||
172 | 'level_img' => $this->level->img($level), |
||
173 | 'date' => $current[1], |
||
174 | 'text' => $current[4], |
||
175 | 'in_file' => isset($current[5]) ? $current[5] : null, |
||
176 | 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) |
||
177 | ); |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | |||
183 | if (empty($log)) { |
||
184 | |||
185 | $lines = explode(PHP_EOL, $file); |
||
186 | $log = []; |
||
187 | |||
188 | foreach ($lines as $key => $line) { |
||
189 | $log[] = [ |
||
190 | 'context' => '', |
||
191 | 'level' => '', |
||
192 | 'level_class' => '', |
||
193 | 'level_img' => '', |
||
194 | 'date' => $key + 1, |
||
195 | 'text' => $line, |
||
196 | 'in_file' => null, |
||
197 | 'stack' => '', |
||
198 | ]; |
||
199 | } |
||
200 | } |
||
201 | |||
202 | return array_reverse($log); |
||
203 | } |
||
204 | |||
279 |