| Conditions | 13 |
| Paths | 10 |
| Total Lines | 48 |
| Code Lines | 34 |
| Lines | 20 |
| Ratio | 41.67 % |
| 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 |
||
| 118 | public function execute($img, $width, $height, $fit, $scale) |
||
| 119 | { |
||
| 120 | $dim = $this->prepareDimensions($img, $width, $height, $fit); |
||
| 121 | |||
| 122 | if (($scale === 'down' && ($dim['width'] >= $img->getWidth() && $dim['height'] >= $img->getHeight())) || |
||
| 123 | ($scale === 'up' && ($dim['width'] <= $img->getWidth() && $dim['height'] <= $img->getHeight()))) { |
||
| 124 | $dim = array('width' => $img->getWidth(), 'height' => $img->getHeight()); |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($dim['width'] <= 0 || $dim['height'] <= 0) { |
||
| 128 | throw new InvalidResizeDimensionException("Both dimensions must be larger than 0."); |
||
| 129 | } |
||
| 130 | |||
| 131 | if ($img->isTransparent() || $img instanceof PaletteImage) { |
||
| 132 | $new = PaletteImage::create($dim['width'], $dim['height']); |
||
| 133 | $new->copyTransparencyFrom($img); |
||
| 134 | |||
| 135 | View Code Duplication | if (!imagecopyresized( |
|
| 136 | $new->getHandle(), |
||
| 137 | $img->getHandle(), |
||
| 138 | 0, 0, 0, 0, |
||
| 139 | $new->getWidth(), |
||
| 140 | $new->getHeight(), |
||
| 141 | $img->getWidth(), |
||
| 142 | $img->getHeight())) { |
||
| 143 | throw new GDFunctionResultException("imagecopyresized() returned false"); |
||
| 144 | } |
||
| 145 | } else { |
||
| 146 | $new = TrueColorImage::create($dim['width'], $dim['height']); |
||
| 147 | $new->alphaBlending(false); |
||
|
|
|||
| 148 | $new->saveAlpha(true); |
||
| 149 | |||
| 150 | View Code Duplication | if (!imagecopyresampled( |
|
| 151 | $new->getHandle(), |
||
| 152 | $img->getHandle(), |
||
| 153 | 0, 0, 0, 0, |
||
| 154 | $new->getWidth(), |
||
| 155 | $new->getHeight(), |
||
| 156 | $img->getWidth(), |
||
| 157 | $img->getHeight())) { |
||
| 158 | throw new GDFunctionResultException("imagecopyresampled() returned false"); |
||
| 159 | } |
||
| 160 | |||
| 161 | $new->alphaBlending(true); |
||
| 162 | } |
||
| 163 | |||
| 164 | return $new; |
||
| 165 | } |
||
| 166 | } |
||
| 167 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: