Conditions | 1 |
Paths | 1 |
Total Lines | 84 |
Code Lines | 48 |
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 |
||
133 | protected function renderFullSize(): void |
||
134 | { |
||
135 | // Create Avatar Object |
||
136 | $avatar = new Avatar($this->skinPath); |
||
137 | |||
138 | // Face |
||
139 | $avatar->render(self::HEAD_BASE_SIZE, Side::FRONT); |
||
140 | |||
141 | $face = new \Imagick(); |
||
142 | $face->readImageBlob((string) $avatar); |
||
143 | $face->brightnessContrastImage(8, 8); |
||
144 | $face->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
||
145 | $face->setBackgroundColor( |
||
146 | $this->getImagickPixelTransparent() |
||
147 | ); |
||
148 | |||
149 | $face->distortImage( |
||
150 | \Imagick::DISTORTION_AFFINE, |
||
151 | $this->getFrontPoints(), |
||
152 | true |
||
153 | ); |
||
154 | |||
155 | // Top |
||
156 | $avatar->render(self::HEAD_BASE_SIZE, Side::TOP); |
||
157 | |||
158 | $top = new \Imagick(); |
||
159 | $top->readImageBlob((string) $avatar); |
||
160 | $top->brightnessContrastImage(6, 6); |
||
161 | $top->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
||
162 | $top->setBackgroundColor( |
||
163 | $this->getImagickPixelTransparent() |
||
164 | ); |
||
165 | |||
166 | $top->distortImage( |
||
167 | \Imagick::DISTORTION_AFFINE, |
||
168 | $this->getTopPoints(), |
||
169 | true |
||
170 | ); |
||
171 | |||
172 | // Right |
||
173 | $avatar->render(self::HEAD_BASE_SIZE, Side::RIGHT); |
||
174 | |||
175 | $right = new \Imagick(); |
||
176 | $right->readImageBlob((string) $avatar); |
||
177 | $right->brightnessContrastImage(4, 4); |
||
178 | |||
179 | $right->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); |
||
180 | $right->setBackgroundColor( |
||
181 | $this->getImagickPixelTransparent() |
||
182 | ); |
||
183 | |||
184 | $right->distortImage( |
||
185 | \Imagick::DISTORTION_AFFINE, |
||
186 | $this->getRightPoints(), |
||
187 | true |
||
188 | ); |
||
189 | |||
190 | // Head image |
||
191 | $doubleAvatarSize = self::HEAD_BASE_SIZE * 2; |
||
192 | $finalImageSize = $doubleAvatarSize + (self::HEAD_MARGIN * 2); |
||
193 | |||
194 | $this->head = new \Imagick(); |
||
195 | $this->head->newImage($finalImageSize, $finalImageSize, $this->getImagickPixelTransparent()); |
||
196 | |||
197 | // This is weird, but it works |
||
198 | $faceX = ((int) round($doubleAvatarSize / 2)) - 2 + self::HEAD_MARGIN; |
||
199 | $faceY = $rightY = ((int) round($doubleAvatarSize / 4)) - 1 + self::HEAD_MARGIN; |
||
200 | $topX = $rightX = ((int) round($doubleAvatarSize / 16)) + self::HEAD_MARGIN; |
||
201 | $topY = -1 + self::HEAD_MARGIN; |
||
202 | |||
203 | // Add Face Section |
||
204 | $this->head->compositeimage($face->getimage(), \Imagick::COMPOSITE_PLUS, $faceX, $faceY); |
||
205 | |||
206 | // Add Top Section |
||
207 | $this->head->compositeimage($top->getimage(), \Imagick::COMPOSITE_PLUS, $topX, $topY); |
||
208 | |||
209 | // Add Right Section |
||
210 | $this->head->compositeimage($right->getimage(), \Imagick::COMPOSITE_PLUS, $rightX, $rightY); |
||
211 | |||
212 | // Set format to PNG |
||
213 | $this->head->setImageFormat('png'); |
||
214 | |||
215 | $this->isometricPath = IsometricsStorage::getPath($this->uuid); |
||
216 | $this->head->writeImage($this->isometricPath); |
||
217 | } |
||
296 |