Conditions | 5 |
Paths | 16 |
Total Lines | 61 |
Code Lines | 38 |
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 |
||
60 | public function render(int $skin_height = 256, $type = self::FRONT): void |
||
61 | { |
||
62 | $type = $this->checkType($type); |
||
63 | $skin_height = $this->checkHeight($skin_height); |
||
64 | |||
65 | $image = $this->createImageFromPng($this->skinPath); |
||
66 | |||
67 | $tmpImageResource = $this->emptyBaseImage(16, 32); |
||
68 | |||
69 | $tmpAvatar = new Avatar($this->skinPath); |
||
70 | $tmpAvatar->render(8, $type); |
||
71 | // Front |
||
72 | if ($type === self::FRONT) { |
||
73 | // Head |
||
74 | \imagecopyresized($tmpImageResource, $tmpAvatar->getResource(), 4, 0, 0, 0, 8, 8, 8, 8); |
||
75 | // Body Front |
||
76 | \imagecopyresized($tmpImageResource, $image, 4, 8, 20, 20, 8, 12, 8, 12); |
||
77 | // Right Arm (left on img) |
||
78 | $r_arm = \imagecreatetruecolor(4, 12); |
||
79 | \imagecopy($r_arm, $image, 0, 0, 44, 20, 4, 12); |
||
|
|||
80 | \imagecopyresized($tmpImageResource, $r_arm, 0, 8, 0, 0, 4, 12, 4, 12); |
||
81 | // Right leg (left on img) |
||
82 | $r_leg = \imagecreatetruecolor(4, 20); |
||
83 | \imagecopy($r_leg, $image, 0, 0, 4, 20, 4, 12); |
||
84 | \imagecopyresized($tmpImageResource, $r_leg, 4, 20, 0, 0, 4, 12, 4, 12); |
||
85 | } else { |
||
86 | // Head |
||
87 | \imagecopyresized($tmpImageResource, $tmpAvatar->getResource(), 4, 0, 0, 0, 8, 8, 8, 8); |
||
88 | // Body Back |
||
89 | \imagecopyresized($tmpImageResource, $image, 4, 8, 32, 20, 8, 12, 8, 12); |
||
90 | // Right Arm Back (left on img) |
||
91 | $r_arm = \imagecreatetruecolor(4, 12); |
||
92 | \imagecopy($r_arm, $image, 0, 0, 52, 20, 4, 12); |
||
93 | \imagecopyresized($tmpImageResource, $r_arm, 0, 8, 0, 0, 4, 12, 4, 12); |
||
94 | // Right leg Back (left on img) |
||
95 | $r_leg = \imagecreatetruecolor(4, 20); |
||
96 | \imagecopy($r_leg, $image, 0, 0, 12, 20, 4, 12); |
||
97 | \imagecopyresized($tmpImageResource, $r_leg, 4, 20, 0, 0, 4, 12, 4, 12); |
||
98 | } |
||
99 | |||
100 | // Left Arm (right flipped) |
||
101 | $l_arm = \imagecreatetruecolor(4, 12); |
||
102 | for ($x = 0; $x < 4; ++$x) { |
||
103 | \imagecopy($l_arm, $r_arm, $x, 0, 4 - $x - 1, 0, 1, 12); |
||
104 | } |
||
105 | \imagecopyresized($tmpImageResource, $l_arm, 12, 8, 0, 0, 4, 12, 4, 12); |
||
106 | // Left leg (right flipped) |
||
107 | $l_leg = \imagecreatetruecolor(4, 20); |
||
108 | for ($x = 0; $x < 4; ++$x) { |
||
109 | \imagecopy($l_leg, $r_leg, $x, 0, 4 - $x - 1, 0, 1, 20); |
||
110 | } |
||
111 | \imagecopyresized($tmpImageResource, $l_leg, 8, 20, 0, 0, 4, 12, 4, 12); |
||
112 | |||
113 | $scale = $skin_height / 32; |
||
114 | if ($scale === 0) { |
||
115 | $scale = 1; |
||
116 | } |
||
117 | $skin_width = (int) \round($scale * (16)); |
||
118 | |||
119 | $this->imgResource = $this->emptyBaseImage($skin_width, $skin_height); |
||
120 | \imagecopyresized($this->imgResource, $tmpImageResource, 0, 0, 0, 0, $skin_width, $skin_height, 16, 32); |
||
121 | } |
||
145 |