Conditions | 12 |
Paths | 11 |
Total Lines | 23 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
95 | function drawLine($image, Point $point1, Point $point2, $color, int $thick = 1): void |
||
96 | { |
||
97 | if (null === $point1 || null === $point2) { |
||
98 | return; |
||
99 | } |
||
100 | if (null === $point1->x || null === $point1->y) { |
||
101 | return; |
||
102 | } |
||
103 | if (null === $point2->x || null === $point2->y) { |
||
104 | return; |
||
105 | } |
||
106 | |||
107 | if ($point1->x === $point2->x) { |
||
108 | $from = $point1->y < $point2->y ? $point1 : $point2; |
||
109 | $to = $point1->y > $point2->y ? $point1 : $point2; |
||
110 | } else { |
||
111 | $from = $point1->x < $point2->x ? $point1 : $point2; |
||
112 | $to = $point1->x > $point2->x ? $point1 : $point2; |
||
113 | } |
||
114 | |||
115 | imagesetthickness($image, $thick); |
||
116 | |||
117 | imageline($image, $from->x, $from->y, $to->x, $to->y, $color); |
||
118 | } |
||
119 |