Conditions | 26 |
Paths | > 20000 |
Total Lines | 195 |
Code Lines | 108 |
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 |
||
25 | public function index() |
||
26 | { |
||
27 | $this->load->language('common/filemanager'); |
||
28 | |||
29 | if (isset($this->request->get['filter_name'])) { |
||
30 | $filter_name = rtrim(str_replace('*', '', $this->request->get['filter_name']), '/'); |
||
31 | } else { |
||
32 | $filter_name = null; |
||
33 | } |
||
34 | |||
35 | // Make sure we have the correct directory |
||
36 | if (isset($this->request->get['directory'])) { |
||
37 | $directory = rtrim($_SERVER['DOCUMENT_ROOT'] . '/images/application/' . str_replace('*', '', $this->request->get['directory']), '/'); |
||
38 | } else { |
||
39 | $directory = $_SERVER['DOCUMENT_ROOT'] . '/images/application'; |
||
40 | } |
||
41 | |||
42 | if (isset($this->request->get['page'])) { |
||
43 | $page = $this->request->get['page']; |
||
44 | } else { |
||
45 | $page = 1; |
||
46 | } |
||
47 | |||
48 | $directories = array(); |
||
49 | $files = array(); |
||
50 | |||
51 | $data['images'] = array(); |
||
52 | |||
53 | |||
54 | |||
55 | //if (substr(str_replace('\\', '/', realpath($directory . '/' . $filter_name)), 0, strlen($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . 'catalog')) == $_SERVER['DOCUMENT_ROOT'] . '/images/application') { |
||
56 | // Get directories |
||
57 | $directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR); |
||
58 | |||
59 | if (!$directories) { |
||
60 | $directories = array(); |
||
61 | } |
||
62 | |||
63 | // Get files |
||
64 | $files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE); |
||
65 | |||
66 | if (!$files) { |
||
67 | $files = array(); |
||
68 | } |
||
69 | //} |
||
70 | |||
71 | // Merge directories and files |
||
72 | $images = array_merge($directories, $files); |
||
73 | |||
74 | // Get total number of files and directories |
||
75 | $image_total = count($images); |
||
76 | |||
77 | // Split the array based on current page number and max number of items per page of 10 |
||
78 | $images = array_splice($images, ($page - 1) * 16, 16); |
||
79 | |||
80 | foreach ($images as $image) { |
||
81 | $name = str_split(basename($image), 14); |
||
82 | |||
83 | if (is_dir($image)) { |
||
84 | $url = ''; |
||
85 | |||
86 | if (isset($this->request->get['target'])) { |
||
87 | $url .= '&target=' . $this->request->get['target']; |
||
88 | } |
||
89 | |||
90 | if (isset($this->request->get['thumb'])) { |
||
91 | $url .= '&thumb=' . $this->request->get['thumb']; |
||
92 | } |
||
93 | |||
94 | $data['images'][] = array( |
||
95 | 'thumb' => '', |
||
96 | 'name' => implode(' ', $name), |
||
97 | 'type' => 'directory', |
||
98 | 'path' => \voku\helper\UTF8::substr($image, \voku\helper\UTF8::strlen($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/')), |
||
99 | 'href' => $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . '&directory=' . urlencode(\voku\helper\UTF8::substr($image, \voku\helper\UTF8::strlen($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . 'application/'))) . $url, true) |
||
100 | ); |
||
101 | } elseif (is_file($image)) { |
||
102 | $data['images'][] = array( |
||
103 | 'thumb' => '/public_html/assets/images/' . \voku\helper\UTF8::substr($image, \voku\helper\UTF8::strlen($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/')), |
||
104 | 'name' => implode(' ', $name), |
||
105 | 'type' => 'image', |
||
106 | 'path' => \voku\helper\UTF8::substr($image, \voku\helper\UTF8::strlen($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/')), |
||
107 | 'href' => '/public_html/assets/images/' . \voku\helper\UTF8::substr($image, \voku\helper\UTF8::strlen($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/')) |
||
108 | ); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | $data['heading_title'] = $this->language->get('heading_title'); |
||
113 | |||
114 | $data['text_no_results'] = $this->language->get('text_no_results'); |
||
115 | $data['text_confirm'] = $this->language->get('text_confirm'); |
||
116 | |||
117 | $data['entry_search'] = $this->language->get('entry_search'); |
||
118 | $data['entry_folder'] = $this->language->get('entry_folder'); |
||
119 | |||
120 | $data['button_parent'] = $this->language->get('button_parent'); |
||
121 | $data['button_refresh'] = $this->language->get('button_refresh'); |
||
122 | $data['button_upload'] = $this->language->get('button_upload'); |
||
123 | $data['button_folder'] = $this->language->get('button_folder'); |
||
124 | $data['button_delete'] = $this->language->get('button_delete'); |
||
125 | $data['button_search'] = $this->language->get('button_search'); |
||
126 | |||
127 | $data['token'] = $this->session->data['token']; |
||
128 | |||
129 | if (isset($this->request->get['directory'])) { |
||
130 | $data['directory'] = urlencode($this->request->get['directory']); |
||
131 | } else { |
||
132 | $data['directory'] = ''; |
||
133 | } |
||
134 | |||
135 | if (isset($this->request->get['filter_name'])) { |
||
136 | $data['filter_name'] = $this->request->get['filter_name']; |
||
137 | } else { |
||
138 | $data['filter_name'] = ''; |
||
139 | } |
||
140 | |||
141 | // Return the target ID for the file manager to set the value |
||
142 | if (isset($this->request->get['target'])) { |
||
143 | $data['target'] = $this->request->get['target']; |
||
144 | } else { |
||
145 | $data['target'] = ''; |
||
146 | } |
||
147 | |||
148 | // Return the thumbnail for the file manager to show a thumbnail |
||
149 | if (isset($this->request->get['thumb'])) { |
||
150 | $data['thumb'] = $this->request->get['thumb']; |
||
151 | } else { |
||
152 | $data['thumb'] = ''; |
||
153 | } |
||
154 | |||
155 | // Parent |
||
156 | $url = ''; |
||
157 | |||
158 | if (isset($this->request->get['directory'])) { |
||
159 | $pos = strrpos($this->request->get['directory'], '/'); |
||
160 | |||
161 | if ($pos) { |
||
162 | $url .= '&directory=' . urlencode(substr($this->request->get['directory'], 0, $pos)); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | if (isset($this->request->get['target'])) { |
||
167 | $url .= '&target=' . $this->request->get['target']; |
||
168 | } |
||
169 | |||
170 | if (isset($this->request->get['thumb'])) { |
||
171 | $url .= '&thumb=' . $this->request->get['thumb']; |
||
172 | } |
||
173 | |||
174 | $data['parent'] = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url, true); |
||
175 | |||
176 | // Refresh |
||
177 | $url = ''; |
||
178 | |||
179 | if (isset($this->request->get['directory'])) { |
||
180 | $url .= '&directory=' . urlencode($this->request->get['directory']); |
||
181 | } |
||
182 | |||
183 | if (isset($this->request->get['target'])) { |
||
184 | $url .= '&target=' . $this->request->get['target']; |
||
185 | } |
||
186 | |||
187 | if (isset($this->request->get['thumb'])) { |
||
188 | $url .= '&thumb=' . $this->request->get['thumb']; |
||
189 | } |
||
190 | |||
191 | $data['refresh'] = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url, true); |
||
192 | |||
193 | $url = ''; |
||
194 | |||
195 | if (isset($this->request->get['directory'])) { |
||
196 | $url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8')); |
||
197 | } |
||
198 | |||
199 | if (isset($this->request->get['filter_name'])) { |
||
200 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
||
201 | } |
||
202 | |||
203 | if (isset($this->request->get['target'])) { |
||
204 | $url .= '&target=' . $this->request->get['target']; |
||
205 | } |
||
206 | |||
207 | if (isset($this->request->get['thumb'])) { |
||
208 | $url .= '&thumb=' . $this->request->get['thumb']; |
||
209 | } |
||
210 | |||
211 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
212 | $pagination->total = $image_total; |
||
213 | $pagination->page = $page; |
||
214 | $pagination->limit = 16; |
||
215 | $pagination->url = $this->url->link('common/filemanager', 'token=' . $this->session->data['token'] . $url . '&page={page}', true); |
||
216 | |||
217 | $data['pagination'] = $pagination->render(); |
||
218 | |||
219 | $this->response->setOutput($this->load->view('common/filemanager', $data)); |
||
220 | } |
||
450 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.