| Conditions | 29 |
| Paths | 144 |
| Total Lines | 82 |
| Code Lines | 52 |
| Lines | 24 |
| Ratio | 29.27 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | 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 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: