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