Conditions | 29 |
Paths | 144 |
Total Lines | 80 |
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 |
||
42 | public function execute($image, $radius, $color, $smoothness, $corners) |
||
43 | { |
||
44 | if ($smoothness < 1) { |
||
45 | $sample_ratio = 1; |
||
46 | } elseif ($smoothness > 16) { |
||
47 | $sample_ratio = 16; |
||
48 | } else { |
||
49 | $sample_ratio = $smoothness; |
||
50 | } |
||
51 | |||
52 | $corner = WideImage::createTrueColorImage($radius * $sample_ratio, $radius * $sample_ratio); |
||
53 | |||
54 | if ($color === null) { |
||
|
|||
55 | imagepalettecopy($corner->getHandle(), $image->getHandle()); |
||
56 | $bg_color = $corner->allocateColor(0, 0, 0); |
||
57 | |||
58 | $corner->fill(0, 0, $bg_color); |
||
59 | $fg_color = $corner->allocateColor(255, 255, 255); |
||
60 | $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); |
||
61 | $corner = $corner->resize($radius, $radius); |
||
62 | |||
63 | $result = $image->asTrueColor(); |
||
64 | |||
65 | $tc = $result->getTransparentColor(); |
||
66 | |||
67 | if ($tc == -1) { |
||
68 | $tc = $result->allocateColorAlpha(255, 255, 255, 127); |
||
69 | imagecolortransparent($result->getHandle(), $tc); |
||
70 | $result->setTransparentColor($tc); |
||
71 | } |
||
72 | |||
73 | if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) { |
||
74 | $result = $result->applyMask($corner, -1, -1); |
||
75 | } |
||
76 | |||
77 | $corner = $corner->rotate(90); |
||
78 | if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) { |
||
79 | $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); |
||
80 | } |
||
81 | |||
82 | $corner = $corner->rotate(90); |
||
83 | if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) { |
||
84 | $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); |
||
85 | } |
||
86 | |||
87 | $corner = $corner->rotate(90); |
||
88 | if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) { |
||
89 | $result = $result->applyMask($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); |
||
90 | } |
||
91 | |||
92 | return $result; |
||
93 | } else { |
||
94 | $bg_color = $color; |
||
95 | |||
96 | $corner->fill(0, 0, $bg_color); |
||
97 | $fg_color = $corner->allocateColorAlpha(127, 127, 127, 127); |
||
98 | $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color); |
||
99 | $corner = $corner->resize($radius, $radius); |
||
100 | |||
101 | $result = $image->copy(); |
||
102 | if ($corners & WideImage::SIDE_TOP_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_TOP) { |
||
103 | $result = $result->merge($corner, -1, -1, 100); |
||
104 | } |
||
105 | |||
106 | $corner = $corner->rotate(90); |
||
107 | if ($corners & WideImage::SIDE_TOP_RIGHT || $corners & WideImage::SIDE_TOP || $corners & WideImage::SIDE_RIGHT) { |
||
108 | $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100); |
||
109 | } |
||
110 | |||
111 | $corner = $corner->rotate(90); |
||
112 | if ($corners & WideImage::SIDE_BOTTOM_RIGHT || $corners & WideImage::SIDE_RIGHT || $corners & WideImage::SIDE_BOTTOM) { |
||
113 | $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100); |
||
114 | } |
||
115 | |||
116 | $corner = $corner->rotate(90); |
||
117 | if ($corners & WideImage::SIDE_BOTTOM_LEFT || $corners & WideImage::SIDE_LEFT || $corners & WideImage::SIDE_BOTTOM) { |
||
118 | $result = $result->merge($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100); |
||
119 | } |
||
120 | |||
121 | return $result; |
||
122 | } |
||
125 |