Conditions | 11 |
Paths | 60 |
Total Lines | 48 |
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 |
||
67 | public function index() |
||
68 | { |
||
69 | $logs = $this->log_viewer->all(); |
||
70 | $levels_counts = $this->log_level->getLevelsCounts($logs); |
||
71 | $folderFiles = []; |
||
72 | |||
73 | if ($this->request->input('f')) { |
||
74 | $this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f'))); |
||
75 | $folderFiles = $this->log_viewer->getFolderFiles(true); |
||
76 | } |
||
77 | if ($this->request->input('l')) { |
||
78 | $this->log_viewer->setFile(Crypt::decrypt($this->request->input('l'))); |
||
79 | } |
||
80 | if ($filter = $this->request->input('filter')) { |
||
81 | if (array_key_exists('level', $filter)) { |
||
82 | $logs = $this->filterByLevel($logs, $filter['level']); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if ($early_return = $this->earlyReturn()) { |
||
87 | return $early_return; |
||
88 | } |
||
89 | |||
90 | $data = [ |
||
91 | 'logs' => $logs, |
||
92 | 'folders' => $this->log_viewer->getFolders(), |
||
93 | 'current_folder' => $this->log_viewer->getFolderName(), |
||
94 | 'folder_files' => $folderFiles, |
||
95 | 'files' => $this->log_viewer->getFiles(true), |
||
96 | 'current_file' => $this->log_viewer->getFileName(), |
||
97 | 'standardFormat' => true, |
||
98 | 'levels_classes' => $this->log_level->getLevelsClasses(), |
||
99 | 'levels_counts' => $levels_counts |
||
100 | ]; |
||
101 | |||
102 | if ($this->request->wantsJson()) { |
||
103 | return $data; |
||
104 | } |
||
105 | |||
106 | if (is_array($data['logs']) && count($data['logs']) > 0) { |
||
107 | $firstLog = reset($data['logs']); |
||
108 | if (!$firstLog['context'] && !$firstLog['level']) { |
||
109 | $data['standardFormat'] = false; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | return app('view')->make($this->view_log, $data); |
||
114 | } |
||
115 | |||
183 |
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.