| Conditions | 13 |
| Paths | 256 |
| Total Lines | 67 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 46 | public function execute($phpthumb) |
||
| 47 | { |
||
| 48 | $currentDimensions = $phpthumb->getCurrentDimensions(); |
||
| 49 | $oldImage = $phpthumb->getOldImage(); |
||
| 50 | |||
| 51 | $borderTop = 0; |
||
| 52 | for (; $borderTop < imagesy($oldImage); ++$borderTop) { |
||
| 53 | for ($x = 0; $x < imagesx($oldImage); ++$x) { |
||
| 54 | if (imagecolorat($oldImage, $x, $borderTop) !== $this->color) { |
||
| 55 | $borderTop -= $this->margin; |
||
| 56 | break 2; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | $borderBottom = 0; |
||
| 62 | for (; $borderBottom < imagesy($oldImage); ++$borderBottom) { |
||
| 63 | for ($x = 0; $x < imagesx($oldImage); ++$x) { |
||
| 64 | if (imagecolorat($oldImage, $x, imagesy($oldImage) - $borderBottom - 1) != $this->color) { |
||
| 65 | $borderBottom -= $this->margin; |
||
| 66 | break 2; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | $borderLeft = 0; |
||
| 72 | for (; $borderLeft < imagesx($oldImage); ++$borderLeft) { |
||
| 73 | for ($y = 0; $y < imagesy($oldImage); ++$y) { |
||
| 74 | if (imagecolorat($oldImage, $borderLeft, $y) !== $this->color) { |
||
| 75 | $borderLeft -= $this->margin; |
||
| 76 | break 2; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | $borderRight = 0; |
||
| 82 | for (; $borderRight < imagesx($oldImage); ++$borderRight) { |
||
| 83 | for ($y = 0; $y < imagesy($oldImage); ++$y) { |
||
| 84 | if (imagecolorat($oldImage, imagesx($oldImage) - $borderRight - 1, $y) !== $this->color) { |
||
| 85 | $borderRight -= $this->margin; |
||
| 86 | break 2; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | $width = imagesx($oldImage) - ($borderLeft + $borderRight); |
||
| 92 | $height = imagesy($oldImage) - ($borderTop + $borderBottom); |
||
| 93 | $workingImage = imagecreatetruecolor($width, $height); |
||
| 94 | |||
| 95 | imagecopy( |
||
| 96 | $workingImage, |
||
| 97 | $oldImage, |
||
| 98 | 0, |
||
| 99 | 0, |
||
| 100 | $borderLeft, |
||
| 101 | $borderTop, |
||
| 102 | $width, |
||
| 103 | $height |
||
| 104 | ); |
||
| 105 | |||
| 106 | $phpthumb->setOldImage($workingImage); |
||
|
|
|||
| 107 | $currentDimensions['width'] = $width; |
||
| 108 | $currentDimensions['height'] = $height; |
||
| 109 | $phpthumb->setCurrentDimensions($currentDimensions); |
||
| 110 | |||
| 111 | return $phpthumb; |
||
| 112 | } |
||
| 113 | } |
||
| 114 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: