| Conditions | 16 |
| Paths | 4 |
| Total Lines | 66 |
| Code Lines | 54 |
| 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 |
||
| 122 | protected function watermarkCanvas(Imagick $image, Imagick $watermark, $position = 'center') |
||
| 123 | { |
||
| 124 | // how big are the images? |
||
| 125 | $iWidth = $image->getImageWidth(); |
||
| 126 | $iHeight = $image->getImageHeight(); |
||
| 127 | $wWidth = $watermark->getImageWidth(); |
||
| 128 | $wHeight = $watermark->getImageHeight(); |
||
| 129 | |||
| 130 | if ($iHeight < $wHeight || $iWidth < $wWidth) { |
||
| 131 | // resize the watermark |
||
| 132 | $watermark->scaleImage($iWidth, $iHeight, true); |
||
| 133 | |||
| 134 | // get new size |
||
| 135 | $wWidth = $watermark->getImageWidth(); |
||
| 136 | $wHeight = $watermark->getImageHeight(); |
||
| 137 | } |
||
| 138 | |||
| 139 | $xOffset = 0; |
||
|
|
|||
| 140 | $yOffset = 0; |
||
| 141 | |||
| 142 | switch ($position) { |
||
| 143 | case 'center': |
||
| 144 | default: |
||
| 145 | $x = ($iWidth - $wWidth) / 2; |
||
| 146 | $y = ($iHeight - $wHeight) / 2; |
||
| 147 | break; |
||
| 148 | case 'topLeft': |
||
| 149 | $x = $xOffset; |
||
| 150 | $y = $yOffset; |
||
| 151 | break; |
||
| 152 | case 'top': |
||
| 153 | case 'topCenter': |
||
| 154 | $x = ($iWidth - $wWidth) / 2; |
||
| 155 | $y = $yOffset; |
||
| 156 | break; |
||
| 157 | case 'topRight': |
||
| 158 | $x = $iWidth - $wWidth - $xOffset; |
||
| 159 | $y = $yOffset; |
||
| 160 | break; |
||
| 161 | case 'right': |
||
| 162 | case 'rightCenter': |
||
| 163 | $x = $iWidth - $wWidth - $xOffset; |
||
| 164 | $y = ($iHeight - $wHeight) / 2; |
||
| 165 | break; |
||
| 166 | case 'bottomRight': |
||
| 167 | $x = $iWidth - $wWidth - $xOffset; |
||
| 168 | $y = $iHeight - $wHeight - $yOffset; |
||
| 169 | break; |
||
| 170 | case 'bottom': |
||
| 171 | case 'bottomCenter': |
||
| 172 | $x = ($iWidth - $wWidth) / 2; |
||
| 173 | $y = $iHeight - $wHeight - $yOffset; |
||
| 174 | break; |
||
| 175 | case 'bottomLeft': |
||
| 176 | $x = $xOffset; |
||
| 177 | $y = $iHeight - $wHeight - $yOffset; |
||
| 178 | break; |
||
| 179 | case 'left': |
||
| 180 | case 'leftCenter': |
||
| 181 | $x = $xOffset; |
||
| 182 | $y = ($iHeight - $wHeight) / 2; |
||
| 183 | break; |
||
| 184 | } |
||
| 185 | |||
| 186 | $image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y); |
||
| 187 | } |
||
| 188 | |||
| 245 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.