Conditions | 16 |
Paths | 157 |
Total Lines | 81 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
120 | protected function storeUploadedFile($target, $mimeType, $uid) |
||
121 | { |
||
122 | $moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
123 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
124 | require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/header.php'; |
||
125 | $this->pathUpload = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH'); |
||
126 | $utility = new Utility(); |
||
127 | $helper = Helper::getInstance(); |
||
128 | // if ( WGGALLERY_PERM_SUBMITAPPR === $permissionsHandler->permGlobalSubmit()) { |
||
129 | // $this->permUseralbum = WGGALLERY_STATE_APPROVAL_VAL; |
||
130 | // } else { |
||
131 | // $this->permUseralbum = WGGALLERY_STATE_ONLINE_VAL; |
||
132 | // } |
||
133 | $this->permUseralbum = 1; //TODO: handle an option, whether images should be online immediately or not |
||
134 | $pathParts = \pathinfo($this->getName()); |
||
|
|||
135 | $this->imageName = \uniqid('img', true) . '.' . \mb_strtolower($pathParts['extension']); |
||
136 | $this->imageNicename = \str_replace(['_', '-'], ' ', $pathParts['filename']); |
||
137 | $this->imageNameLarge = \uniqid('imgl', true) . '.' . \mb_strtolower($pathParts['extension']); |
||
138 | $this->imagePath = $this->pathUpload . '/large/' . $this->imageNameLarge; |
||
139 | if (!\move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $this->imagePath)) { |
||
140 | return false; |
||
141 | } |
||
142 | $this->imageNameOrig = $_FILES[$this->inputName]['name']; |
||
143 | $this->imageMimetype = $_FILES[$this->inputName]['type']; |
||
144 | $this->imageSize = $_FILES[$this->inputName]['size']; |
||
145 | $ret = $this->handleImageDB(); |
||
146 | if (!$ret) { |
||
147 | return [ |
||
148 | 'error' => \sprintf(\_FAILSAVEIMG, $this->imageNicename), |
||
149 | ]; |
||
150 | } |
||
151 | // load watermark settings |
||
152 | $albumObj = $albumsHandler->get($this->claims->cat); |
||
153 | $wmId = $albumObj->getVar('alb_wmid'); |
||
154 | $wmTargetM = false; |
||
155 | $wmTargetL = false; |
||
156 | if ($wmId > 0) { |
||
157 | $watermarksObj = $watermarksHandler->get($wmId); |
||
158 | $wmTarget = $watermarksObj->getVar('wm_target'); |
||
159 | if (\constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_A') === $wmTarget || \constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_M') === $wmTarget) { |
||
160 | $wmTargetM = true; |
||
161 | } |
||
162 | if (\constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_A') === $wmTarget || \constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_L') === $wmTarget) { |
||
163 | $wmTargetL = true; |
||
164 | } |
||
165 | } |
||
166 | // create medium image |
||
167 | // $ret = $this->resizeImage($this->pathUpload . '/medium/' . $this->imageName, $helper->getConfig('maxwidth_medium'), $helper->getConfig('maxheight_medium')); |
||
168 | $ret = $utility->resizeImage($this->imagePath, $this->pathUpload . '/medium/' . $this->imageName, $helper->getConfig('maxwidth_medium'), $helper->getConfig('maxheight_medium'), $this->imageMimetype); |
||
169 | if (false === $ret) { |
||
170 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEIMG_MEDIUM'), $this->imageNicename)]; |
||
171 | } |
||
172 | if ('copy' === $ret) { |
||
173 | \copy($this->pathUpload . '/large/' . $this->imageNameLarge, $this->pathUpload . '/medium/' . $this->imageName); |
||
174 | } |
||
175 | // create thumb |
||
176 | // $ret = $this->resizeImage($this->pathUpload . '/thumbs/' . $this->imageName, $helper->getConfig('maxwidth_thumbs'), $helper->getConfig('maxheight_thumbs')); |
||
177 | $ret = $utility->resizeImage($this->imagePath, $this->pathUpload . '/thumbs/' . $this->imageName, $helper->getConfig('maxwidth_thumbs'), $helper->getConfig('maxheight_thumbs'), $this->imageMimetype); |
||
178 | if (false === $ret) { |
||
179 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEIMG_THUMBS'), $this->imageNicename)]; |
||
180 | } |
||
181 | if ('copy' === $ret) { |
||
182 | \copy($this->pathUpload . '/large/' . $this->imageNameLarge, $this->pathUpload . '/thumbs/' . $this->imageName); |
||
183 | } |
||
184 | // add watermark to large image |
||
185 | if ($wmTargetL) { |
||
186 | $imgWm = $this->pathUpload . '/large/' . $this->imageNameLarge; |
||
187 | $resWm = $watermarksHandler->watermarkImage($wmId, $imgWm, $imgWm); |
||
188 | if (true !== $resWm) { |
||
189 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEWM_LARGE'), $this->imageNicename, $resWm)]; |
||
190 | } |
||
191 | } |
||
192 | // add watermark to medium image |
||
193 | if ($wmTargetM) { |
||
194 | $imgWm = $this->pathUpload . '/medium/' . $this->imageName; |
||
195 | $resWm = $watermarksHandler->watermarkImage($wmId, $imgWm, $imgWm); |
||
196 | if (true !== $resWm) { |
||
197 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEWM_MEDIUM'), $this->imageNicename, $resWm)]; |
||
198 | } |
||
199 | } |
||
200 | return ['success' => true, 'uuid' => $uuid]; |
||
201 | } |
||
271 |