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