Conditions | 16 |
Paths | 157 |
Total Lines | 133 |
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 declare(strict_types=1); |
||
135 | protected function storeUploadedFile($target, $mimeType, $uid) |
||
136 | { |
||
137 | $moduleDirName = \basename(\dirname(\dirname(__DIR__))); |
||
138 | |||
139 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
140 | |||
141 | require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/header.php'; |
||
142 | |||
143 | $this->pathUpload = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH'); |
||
144 | |||
145 | $utility = new Utility(); |
||
146 | |||
147 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||
148 | |||
149 | $helper = Helper::getInstance(); |
||
150 | |||
151 | // if ( WGGALLERY_PERM_SUBMITAPPR === $permissionsHandler->permGlobalSubmit()) { |
||
152 | |||
153 | // $this->permUseralbum = WGGALLERY_STATE_APPROVAL_VAL; |
||
154 | |||
155 | // } else { |
||
156 | |||
157 | // $this->permUseralbum = WGGALLERY_STATE_ONLINE_VAL; |
||
158 | |||
159 | // } |
||
160 | |||
161 | $this->permUseralbum = 1; //TODO: handle an option, whether images should be online immediately or not |
||
162 | |||
163 | $pathParts = \pathinfo($this->getName()); |
||
|
|||
164 | |||
165 | $this->imageName = \uniqid('img', true) . '.' . \mb_strtolower($pathParts['extension']); |
||
166 | |||
167 | $this->imageNicename = \str_replace(['_', '-'], ' ', $pathParts['filename']); |
||
168 | |||
169 | $this->imageNameLarge = \uniqid('imgl', true) . '.' . \mb_strtolower($pathParts['extension']); |
||
170 | |||
171 | $this->imagePath = $this->pathUpload . '/large/' . $this->imageNameLarge; |
||
172 | |||
173 | if (!\move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $this->imagePath)) { |
||
174 | return false; |
||
175 | } |
||
176 | |||
177 | $this->imageNameOrig = $_FILES[$this->inputName]['name']; |
||
178 | |||
179 | $this->imageMimetype = $_FILES[$this->inputName]['type']; |
||
180 | |||
181 | $this->imageSize = $_FILES[$this->inputName]['size']; |
||
182 | |||
183 | $ret = $this->handleImageDB(); |
||
184 | |||
185 | if (!$ret) { |
||
186 | return [ |
||
187 | 'error' => \sprintf(\_FAILSAVEIMG, $this->imageNicename), |
||
188 | ]; |
||
189 | } |
||
190 | |||
191 | // load watermark settings |
||
192 | |||
193 | $albumObj = $albumsHandler->get($this->claims->cat); |
||
194 | |||
195 | $wmId = $albumObj->getVar('alb_wmid'); |
||
196 | |||
197 | $wmTargetM = false; |
||
198 | |||
199 | $wmTargetL = false; |
||
200 | |||
201 | if ($wmId > 0) { |
||
202 | $watermarksObj = $watermarksHandler->get($wmId); |
||
203 | |||
204 | $wmTarget = $watermarksObj->getVar('wm_target'); |
||
205 | |||
206 | if (\constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_A') === $wmTarget || \constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_M') === $wmTarget) { |
||
207 | $wmTargetM = true; |
||
208 | } |
||
209 | |||
210 | if (\constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_A') === $wmTarget || \constant($moduleDirNameUpper . '_' . 'WATERMARK_TARGET_L') === $wmTarget) { |
||
211 | $wmTargetL = true; |
||
212 | } |
||
213 | } |
||
214 | |||
215 | // create medium image |
||
216 | |||
217 | // $ret = $this->resizeImage($this->pathUpload . '/medium/' . $this->imageName, $helper->getConfig('maxwidth_medium'), $helper->getConfig('maxheight_medium')); |
||
218 | |||
219 | $ret = $utility->resizeImage($this->imagePath, $this->pathUpload . '/medium/' . $this->imageName, $helper->getConfig('maxwidth_medium'), $helper->getConfig('maxheight_medium'), $this->imageMimetype); |
||
220 | |||
221 | if (false === $ret) { |
||
222 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEIMG_MEDIUM'), $this->imageNicename)]; |
||
223 | } |
||
224 | |||
225 | if ('copy' === $ret) { |
||
226 | \copy($this->pathUpload . '/large/' . $this->imageNameLarge, $this->pathUpload . '/medium/' . $this->imageName); |
||
227 | } |
||
228 | |||
229 | // create thumb |
||
230 | |||
231 | // $ret = $this->resizeImage($this->pathUpload . '/thumbs/' . $this->imageName, $helper->getConfig('maxwidth_thumbs'), $helper->getConfig('maxheight_thumbs')); |
||
232 | |||
233 | $ret = $utility->resizeImage($this->imagePath, $this->pathUpload . '/thumbs/' . $this->imageName, $helper->getConfig('maxwidth_thumbs'), $helper->getConfig('maxheight_thumbs'), $this->imageMimetype); |
||
234 | |||
235 | if (false === $ret) { |
||
236 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEIMG_THUMBS'), $this->imageNicename)]; |
||
237 | } |
||
238 | |||
239 | if ('copy' === $ret) { |
||
240 | \copy($this->pathUpload . '/large/' . $this->imageNameLarge, $this->pathUpload . '/thumbs/' . $this->imageName); |
||
241 | } |
||
242 | |||
243 | // add watermark to large image |
||
244 | |||
245 | if ($wmTargetL) { |
||
246 | $imgWm = $this->pathUpload . '/large/' . $this->imageNameLarge; |
||
247 | |||
248 | $resWm = $watermarksHandler->watermarkImage($wmId, $imgWm, $imgWm); |
||
249 | |||
250 | if (true !== $resWm) { |
||
251 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEWM_LARGE'), $this->imageNicename, $resWm)]; |
||
252 | } |
||
253 | } |
||
254 | |||
255 | // add watermark to medium image |
||
256 | |||
257 | if ($wmTargetM) { |
||
258 | $imgWm = $this->pathUpload . '/medium/' . $this->imageName; |
||
259 | |||
260 | $resWm = $watermarksHandler->watermarkImage($wmId, $imgWm, $imgWm); |
||
261 | |||
262 | if (true !== $resWm) { |
||
263 | return ['error' => \sprintf(\constant($moduleDirNameUpper . '_' . 'FAILSAVEWM_MEDIUM'), $this->imageNicename, $resWm)]; |
||
264 | } |
||
265 | } |
||
266 | |||
267 | return ['success' => true, 'uuid' => $uuid]; |
||
268 | } |
||
368 |