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