Conditions | 12 |
Paths | 15 |
Total Lines | 22 |
Code Lines | 17 |
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 |
||
69 | public function getImageAt($width = null, $height = null, $upscale = false) |
||
70 | { |
||
71 | if (!$this->owner->exists()) { |
||
72 | return $this->owner; |
||
73 | } |
||
74 | |||
75 | $realWidth = $this->owner->getWidth(); |
||
76 | $realHeight = $this->owner->getHeight(); |
||
77 | |||
78 | if ($width && $height) { |
||
79 | return $realWidth < $width && $realHeight < $height && !$upscale |
||
80 | ? $this->owner |
||
81 | : $this->owner->Pad($width, $height); |
||
82 | } else { |
||
83 | if ($width) { |
||
84 | return $realWidth < $width && !$upscale |
||
85 | ? $this->owner |
||
86 | : $this->owner->ScaleWidth($width); |
||
87 | } else { |
||
88 | return $realHeight < $height && !$upscale |
||
89 | ? $this->owner |
||
90 | : $this->owner->ScaleHeight($height); |
||
91 | } |
||
104 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: