| Conditions | 1 |
| Paths | 1 |
| Total Lines | 84 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 186 | protected function renderFullSize(): void |
||
| 187 | { |
||
| 188 | // Create Avatar Object |
||
| 189 | $avatar = new Avatar($this->skinPath); |
||
| 190 | |||
| 191 | // Face |
||
| 192 | $avatar->render(self::HEAD_BASE_SIZE, ImageSection::FRONT); |
||
| 193 | |||
| 194 | $face = new \Imagick(); |
||
| 195 | $face->readImageBlob((string) $avatar); |
||
| 196 | $face->brightnessContrastImage(8, 8); |
||
| 197 | $face->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
||
| 198 | $face->setBackgroundColor( |
||
| 199 | $this->getImagickPixelTransparent() |
||
| 200 | ); |
||
| 201 | |||
| 202 | $face->distortImage( |
||
| 203 | \Imagick::DISTORTION_AFFINE, |
||
| 204 | $this->getFrontPoints(), |
||
| 205 | true |
||
| 206 | ); |
||
| 207 | |||
| 208 | // Top |
||
| 209 | $avatar->render(self::HEAD_BASE_SIZE, ImageSection::TOP); |
||
| 210 | |||
| 211 | $top = new \Imagick(); |
||
| 212 | $top->readImageBlob((string) $avatar); |
||
| 213 | $top->brightnessContrastImage(6, 6); |
||
| 214 | $top->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
||
| 215 | $top->setBackgroundColor( |
||
| 216 | $this->getImagickPixelTransparent() |
||
| 217 | ); |
||
| 218 | |||
| 219 | $top->distortImage( |
||
| 220 | \Imagick::DISTORTION_AFFINE, |
||
| 221 | $this->getTopPoints(), |
||
| 222 | true |
||
| 223 | ); |
||
| 224 | |||
| 225 | // Right |
||
| 226 | $avatar->render(self::HEAD_BASE_SIZE, ImageSection::RIGHT); |
||
| 227 | |||
| 228 | $right = new \Imagick(); |
||
| 229 | $right->readImageBlob((string) $avatar); |
||
| 230 | $right->brightnessContrastImage(4, 4); |
||
| 231 | |||
| 232 | $right->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
||
| 233 | $right->setBackgroundColor( |
||
| 234 | $this->getImagickPixelTransparent() |
||
| 235 | ); |
||
| 236 | |||
| 237 | $right->distortImage( |
||
| 238 | \Imagick::DISTORTION_AFFINE, |
||
| 239 | $this->getRightPoints(), |
||
| 240 | true |
||
| 241 | ); |
||
| 242 | |||
| 243 | // Head image |
||
| 244 | $doubleAvatarSize = self::HEAD_BASE_SIZE * 2; |
||
| 245 | $finalImageSize = $doubleAvatarSize + (self::HEAD_MARGIN * 2); |
||
| 246 | |||
| 247 | $this->head = new \Imagick(); |
||
| 248 | $this->head->newImage($finalImageSize, $finalImageSize, $this->getImagickPixelTransparent()); |
||
| 249 | |||
| 250 | // This is weird, but it works |
||
| 251 | $faceX = ((int) \round(($doubleAvatarSize / 2))) - 2 + self::HEAD_MARGIN; |
||
| 252 | $faceY = $rightY = ((int) \round($doubleAvatarSize / 4)) - 1 + self::HEAD_MARGIN; |
||
| 253 | $topX = $rightX = ((int) \round($doubleAvatarSize / 16)) + self::HEAD_MARGIN; |
||
| 254 | $topY = -1 + self::HEAD_MARGIN; |
||
| 255 | |||
| 256 | // Add Face Section |
||
| 257 | $this->head->compositeimage($face->getimage(), \Imagick::COMPOSITE_PLUS, $faceX, $faceY); |
||
| 258 | |||
| 259 | // Add Top Section |
||
| 260 | $this->head->compositeimage($top->getimage(), \Imagick::COMPOSITE_PLUS, $topX, $topY); |
||
| 261 | |||
| 262 | // Add Right Section |
||
| 263 | $this->head->compositeimage($right->getimage(), \Imagick::COMPOSITE_PLUS, $rightX, $rightY); |
||
| 264 | |||
| 265 | // Set format to PNG |
||
| 266 | $this->head->setImageFormat('png'); |
||
| 267 | |||
| 268 | $this->isometricPath = IsometricsStorage::getPath($this->uuid); |
||
| 269 | $this->head->writeImage($this->isometricPath); |
||
| 270 | } |
||
| 322 |