| Conditions | 18 |
| Paths | 209 |
| Total Lines | 58 |
| Code Lines | 37 |
| Lines | 20 |
| Ratio | 34.48 % |
| 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 |
||
| 49 | protected function prepareDimensions($img, $width, $height, $fit) |
||
| 50 | { |
||
| 51 | if ($width === null && $height === null) { |
||
| 52 | return array('width' => $img->getWidth(), 'height' => $img->getHeight()); |
||
| 53 | } |
||
| 54 | |||
| 55 | View Code Duplication | if ($width !== null) { |
|
| 56 | $width = Coordinate::fix($width, $img->getWidth()); |
||
| 57 | $rx = $img->getWidth() / $width; |
||
| 58 | } else { |
||
| 59 | $rx = null; |
||
| 60 | } |
||
| 61 | |||
| 62 | View Code Duplication | if ($height !== null) { |
|
| 63 | $height = Coordinate::fix($height, $img->getHeight()); |
||
| 64 | $ry = $img->getHeight() / $height; |
||
| 65 | } else { |
||
| 66 | $ry = null; |
||
| 67 | } |
||
| 68 | |||
| 69 | View Code Duplication | if ($rx === null && $ry !== null) { |
|
| 70 | $rx = $ry; |
||
| 71 | $width = round($img->getWidth() / $rx); |
||
| 72 | } |
||
| 73 | |||
| 74 | View Code Duplication | if ($ry === null && $rx !== null) { |
|
| 75 | $ry = $rx; |
||
| 76 | $height = round($img->getHeight() / $ry); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($width === 0 || $height === 0) { |
||
| 80 | return array('width' => 0, 'height' => 0); |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($fit == null) { |
||
| 84 | $fit = 'inside'; |
||
| 85 | } |
||
| 86 | |||
| 87 | $dim = array(); |
||
| 88 | |||
| 89 | if ($fit == 'fill') { |
||
| 90 | $dim['width'] = $width; |
||
| 91 | $dim['height'] = $height; |
||
| 92 | } elseif ($fit == 'inside' || $fit == 'outside') { |
||
| 93 | if ($fit == 'inside') { |
||
| 94 | $ratio = ($rx > $ry) ? $rx : $ry; |
||
| 95 | } else { |
||
| 96 | $ratio = ($rx < $ry) ? $rx : $ry; |
||
| 97 | } |
||
| 98 | |||
| 99 | $dim['width'] = round($img->getWidth() / $ratio); |
||
| 100 | $dim['height'] = round($img->getHeight() / $ratio); |
||
| 101 | } else { |
||
| 102 | throw new InvalidFitMethodException("{$fit} is not a valid resize-fit method."); |
||
| 103 | } |
||
| 104 | |||
| 105 | return $dim; |
||
| 106 | } |
||
| 107 | |||
| 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: