| Conditions | 11 |
| Paths | 34 |
| Total Lines | 48 |
| Code Lines | 27 |
| 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 |
||
| 86 | protected function validateLimitsUpload() |
||
| 87 | { |
||
| 88 | $files = $this->request->file('files'); |
||
| 89 | |||
| 90 | if (!gplcart_file_multi_upload($files)) { |
||
| 91 | return false; |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($this->user->isSuperadmin()) { |
||
| 95 | return true; |
||
| 96 | } |
||
| 97 | |||
| 98 | $role_id = $this->user->getRoleId(); |
||
| 99 | $settings = $this->module->getSettings('file_manager'); |
||
| 100 | |||
| 101 | $maxfilesize = 0; |
||
| 102 | $extensions = array(); |
||
| 103 | |||
| 104 | if (!empty($settings['filesize_limit'][$role_id])) { |
||
| 105 | $maxfilesize = $settings['filesize_limit'][$role_id]; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (!empty($settings['extension_limit'][$role_id])) { |
||
| 109 | $extensions = $settings['extension_limit'][$role_id]; |
||
| 110 | } |
||
| 111 | |||
| 112 | $errors = array(); |
||
| 113 | foreach ($files as $file) { |
||
| 114 | |||
| 115 | if ($maxfilesize && filesize($file['tmp_name']) > $maxfilesize) { |
||
| 116 | unlink($file['tmp_name']); |
||
| 117 | $errors[] = "{$file['name']}: " . $this->translation->text('File size exceeds %num bytes', array('%num' => $maxfilesize)); |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($extensions && !in_array(pathinfo($file['name'], PATHINFO_EXTENSION), $extensions)) { |
||
| 122 | unlink($file['tmp_name']); |
||
| 123 | $errors[] = "{$file['name']}: " . $this->translation->text('Unsupported file extension'); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | if (empty($errors)) { |
||
| 128 | return true; |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->setError('files', implode('<br>', $errors)); |
||
| 132 | return false; |
||
| 133 | } |
||
| 134 | |||
| 162 |