| Conditions | 10 |
| Paths | 16 |
| Total Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 1 | 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 |
||
| 31 | public function index() |
||
| 32 | { |
||
| 33 | |||
| 34 | if ($this->request->input('l')) { |
||
| 35 | LaravelLogViewer::setFile(Crypt::decrypt($this->request->input('l'))); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($this->request->input('dl')) { |
||
| 39 | return $this->download($this->pathFromInput('dl')); |
||
| 40 | } elseif ($this->request->has('clean')) { |
||
| 41 | app('files')->put($this->pathFromInput('clean'), ''); |
||
| 42 | return $this->redirect($this->request->url()); |
||
| 43 | } elseif ($this->request->has('del')) { |
||
| 44 | app('files')->delete($this->pathFromInput('del')); |
||
| 45 | return $this->redirect($this->request->url()); |
||
| 46 | } elseif ($this->request->has('delall')) { |
||
| 47 | foreach(LaravelLogViewer::getFiles(true) as $file){ |
||
| 48 | app('files')->delete(LaravelLogViewer::pathToLogFile($file)); |
||
| 49 | } |
||
| 50 | return $this->redirect($this->request->url()); |
||
| 51 | } |
||
| 52 | |||
| 53 | $data = [ |
||
| 54 | 'logs' => LaravelLogViewer::all(), |
||
| 55 | 'files' => LaravelLogViewer::getFiles(true), |
||
| 56 | 'current_file' => LaravelLogViewer::getFileName(), |
||
| 57 | 'standardFormat' => true, |
||
| 58 | ]; |
||
| 59 | |||
| 60 | if ($this->request->wantsJson()) { |
||
| 61 | return $data; |
||
| 62 | } |
||
| 63 | |||
| 64 | $firstLog = reset($data['logs']); |
||
| 65 | if (!$firstLog['context'] && !$firstLog['level']) { |
||
| 66 | $data['standardFormat'] = false; |
||
| 67 | } |
||
| 68 | |||
| 69 | return app('view')->make('laravel-log-viewer::log', $data); |
||
| 70 | } |
||
| 71 | |||
| 109 |
This check looks for classes that have been defined more than once in the same file.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.