| Conditions | 17 |
| Paths | 2 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 65 | public function loadFromFile($file){ |
||
| 66 | |||
| 67 | $res = @imagecreatefromjpeg($file); |
||
| 68 | |||
| 69 | if(!$res){ |
||
|
|
|||
| 70 | $width = imagesx($res); |
||
| 71 | $height = imagesy($res); |
||
| 72 | |||
| 73 | $new_tab = array(); |
||
| 74 | for($y = 0; $y <= $height; $y++){ |
||
| 75 | for($x = 0; $x <= $width; $x++){ |
||
| 76 | if($y==$height || $x==$width){ |
||
| 77 | $color = 10; |
||
| 78 | }else{ |
||
| 79 | $color = imagecolorat($res, $x, $y); |
||
| 80 | if(!$color) $color = 255; |
||
| 81 | } |
||
| 82 | $new_tab[$x][$y] = $color; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | $this->x_w = $width; |
||
| 87 | $this->y_h = $height; |
||
| 88 | |||
| 89 | $modX = ceil($width/2); |
||
| 90 | $modY = ceil($height/2); |
||
| 91 | |||
| 92 | $relations = array(); |
||
| 93 | for($y = 0; $y <= $height; $y++){ |
||
| 94 | for($x = 0; $x <= $width; $x++){ |
||
| 95 | |||
| 96 | if($new_tab[$x][$y]<=100){ |
||
| 97 | $k3 = 9999; |
||
| 98 | }else{ |
||
| 99 | $k = $x; $k2 = $y; |
||
| 100 | if($x<$modX) $k = $width-$x; |
||
| 101 | if($y<$modY) $k2 = $height-$y; |
||
| 102 | $k3 = $k; |
||
| 103 | if($k2>$k) $k3 = $k2; |
||
| 104 | } |
||
| 105 | $tmpX = $x-1; $tmpY = $y; |
||
| 106 | if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
||
| 107 | |||
| 108 | $tmpX2 = $x+1; $tmpY2 = $y; |
||
| 109 | if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
||
| 110 | |||
| 111 | $tmpX3 = $x; $tmpY3 = $y-1; |
||
| 112 | if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
||
| 113 | |||
| 114 | $tmpX4 = $x; $tmpY4 = $y+1; |
||
| 115 | if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | $relations = $res; |
||
| 119 | } |
||
| 120 | |||
| 121 | return $relations; |
||
| 122 | } |
||
| 144 |