| Conditions | 10 |
| Paths | 6 |
| Total Lines | 36 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| Changes | 5 | ||
| Bugs | 0 | Features | 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 |
||
| 20 | protected function parseCropParameter($crop) |
||
| 21 | { |
||
| 22 | if ($crop) { |
||
| 23 | /* @var ResourceImageDOInterface $resource */ |
||
| 24 | $resource = $this->resourceDO; |
||
| 25 | $crop = explode('x', $crop); |
||
|
1 ignored issue
–
show
|
|||
| 26 | if (count($crop) != 4) { |
||
| 27 | throw new WrongRequestException('Crop parameter has to consist of four parts, concatenated by "x" char.'); |
||
| 28 | } |
||
| 29 | |||
| 30 | $cropObject = new CropImageDO(); |
||
| 31 | $cropObject->setX((int) $crop[0]); |
||
| 32 | $cropObject->setY((int) $crop[1]); |
||
| 33 | $cropObject->setWidth((int) $crop[2]); |
||
| 34 | $cropObject->setHeight((int) $crop[3]); |
||
| 35 | |||
| 36 | if (!$resource->getWidth() || !$cropObject->getHeight()) { |
||
| 37 | throw new WrongRequestException('You should send the size=[X]x[Y] parameter together with the crop parameter'); |
||
| 38 | } |
||
| 39 | if ($cropObject->getX() < 0 || $cropObject->getY() < 0 || |
||
| 40 | $cropObject->getWidth() < 1 || $cropObject->getHeight() < 1 |
||
| 41 | ) { |
||
| 42 | throw new WrongRequestException('Crop parameters can not be less than zero'); |
||
| 43 | } |
||
| 44 | |||
| 45 | $resizeRatio = $resource->getWidth() / $resource->getHeight(); |
||
| 46 | $cropRatio = $cropObject->getWidth() / $cropObject->getHeight(); |
||
|
1 ignored issue
–
show
|
|||
| 47 | |||
| 48 | if ($resizeRatio !== $cropRatio) { |
||
| 49 | throw new WrongRequestException('Wrong width to height ratio in crop parameter. |
||
| 50 | It should be same as width to height ratio in size parameter'); |
||
| 51 | } |
||
| 52 | |||
| 53 | $resource->setCrop($cropObject); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 83 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.