| Conditions | 16 |
| Paths | 4 |
| Total Lines | 66 |
| 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 |
||
| 141 | protected function watermarkCanvas(Imagick $image, Imagick $watermark, $position = 'center') |
||
| 142 | { |
||
| 143 | // how big are the images? |
||
| 144 | $iWidth = $image->getImageWidth(); |
||
| 145 | $iHeight = $image->getImageHeight(); |
||
| 146 | $wWidth = $watermark->getImageWidth(); |
||
| 147 | $wHeight = $watermark->getImageHeight(); |
||
| 148 | |||
| 149 | if ($iHeight < $wHeight || $iWidth < $wWidth) { |
||
| 150 | // resize the watermark |
||
| 151 | $watermark->scaleImage($iWidth, $iHeight, true); |
||
| 152 | |||
| 153 | // get new size |
||
| 154 | $wWidth = $watermark->getImageWidth(); |
||
| 155 | $wHeight = $watermark->getImageHeight(); |
||
| 156 | } |
||
| 157 | |||
| 158 | $xOffset = 0; |
||
|
|
|||
| 159 | $yOffset = 0; |
||
| 160 | |||
| 161 | switch ($position) { |
||
| 162 | case 'center': |
||
| 163 | default: |
||
| 164 | $x = ($iWidth - $wWidth) / 2; |
||
| 165 | $y = ($iHeight - $wHeight) / 2; |
||
| 166 | break; |
||
| 167 | case 'topLeft': |
||
| 168 | $x = $xOffset; |
||
| 169 | $y = $yOffset; |
||
| 170 | break; |
||
| 171 | case 'top': |
||
| 172 | case 'topCenter': |
||
| 173 | $x = ($iWidth - $wWidth) / 2; |
||
| 174 | $y = $yOffset; |
||
| 175 | break; |
||
| 176 | case 'topRight': |
||
| 177 | $x = $iWidth - $wWidth - $xOffset; |
||
| 178 | $y = $yOffset; |
||
| 179 | break; |
||
| 180 | case 'right': |
||
| 181 | case 'rightCenter': |
||
| 182 | $x = $iWidth - $wWidth - $xOffset; |
||
| 183 | $y = ($iHeight - $wHeight) / 2; |
||
| 184 | break; |
||
| 185 | case 'bottomRight': |
||
| 186 | $x = $iWidth - $wWidth - $xOffset; |
||
| 187 | $y = $iHeight - $wHeight - $yOffset; |
||
| 188 | break; |
||
| 189 | case 'bottom': |
||
| 190 | case 'bottomCenter': |
||
| 191 | $x = ($iWidth - $wWidth) / 2; |
||
| 192 | $y = $iHeight - $wHeight - $yOffset; |
||
| 193 | break; |
||
| 194 | case 'bottomLeft': |
||
| 195 | $x = $xOffset; |
||
| 196 | $y = $iHeight - $wHeight - $yOffset; |
||
| 197 | break; |
||
| 198 | case 'left': |
||
| 199 | case 'leftCenter': |
||
| 200 | $x = $xOffset; |
||
| 201 | $y = ($iHeight - $wHeight) / 2; |
||
| 202 | break; |
||
| 203 | } |
||
| 204 | |||
| 205 | $image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y); |
||
| 206 | } |
||
| 207 | |||
| 289 |
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.