| Conditions | 15 |
| Paths | 1188 |
| Total Lines | 102 |
| Code Lines | 68 |
| 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 |
||
| 91 | public function Stroke($img, $xscale, $yscale) |
||
| 92 | { |
||
| 93 | $n = $this->numpoints; |
||
| 94 | if ($this->center) { |
||
| 95 | --$n; |
||
| 96 | } |
||
| 97 | |||
| 98 | if (isset($this->coords[1])) { |
||
| 99 | if (safe_count($this->coords[1]) != $n) { |
||
| 100 | Util\JpGraphError::RaiseL(2003, safe_count($this->coords[1]), $n); |
||
| 101 | // ("Number of X and Y points are not equal. Number of X-points:". safe_count($this->coords[1])." Number of Y-points:$numpoints"); |
||
| 102 | } else { |
||
| 103 | $exist_x = true; |
||
| 104 | } |
||
| 105 | } else { |
||
| 106 | $exist_x = false; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($exist_x) { |
||
|
|
|||
| 110 | $xs = $this->coords[1][0]; |
||
| 111 | } else { |
||
| 112 | $xs = 0; |
||
| 113 | } |
||
| 114 | |||
| 115 | $ts = $this->iTupleSize; |
||
| 116 | $this->csimareas = ''; |
||
| 117 | for ($i = 0; $i < $n; ++$i) { |
||
| 118 | //If value is NULL, then don't draw a bar at all |
||
| 119 | if ($this->coords[0][$i * $ts] === null) { |
||
| 120 | continue; |
||
| 121 | } |
||
| 122 | |||
| 123 | if ($exist_x) { |
||
| 124 | $x = $this->coords[1][$i]; |
||
| 125 | if ($x === null) { |
||
| 126 | continue; |
||
| 127 | } |
||
| 128 | } else { |
||
| 129 | $x = $i; |
||
| 130 | } |
||
| 131 | $xt = $xscale->Translate($x); |
||
| 132 | |||
| 133 | $neg = $this->coords[0][$i * $ts] > $this->coords[0][$i * $ts + 1]; |
||
| 134 | $yopen = $yscale->Translate($this->coords[0][$i * $ts]); |
||
| 135 | $yclose = $yscale->Translate($this->coords[0][$i * $ts + 1]); |
||
| 136 | $ymin = $yscale->Translate($this->coords[0][$i * $ts + 2]); |
||
| 137 | $ymax = $yscale->Translate($this->coords[0][$i * $ts + 3]); |
||
| 138 | |||
| 139 | $dx = floor($this->iWidth / 2); |
||
| 140 | $xl = $xt - $dx; |
||
| 141 | $xr = $xt + $dx; |
||
| 142 | |||
| 143 | if ($neg) { |
||
| 144 | $img->SetColor($this->iStockColor3); |
||
| 145 | } else { |
||
| 146 | $img->SetColor($this->iStockColor1); |
||
| 147 | } |
||
| 148 | $img->FilledRectangle($xl, $yopen, $xr, $yclose); |
||
| 149 | $img->SetLineWeight($this->weight); |
||
| 150 | if ($neg) { |
||
| 151 | $img->SetColor($this->iStockColor2); |
||
| 152 | } else { |
||
| 153 | $img->SetColor($this->color); |
||
| 154 | } |
||
| 155 | |||
| 156 | $img->Rectangle($xl, $yopen, $xr, $yclose); |
||
| 157 | |||
| 158 | if ($yopen < $yclose) { |
||
| 159 | $ytop = $yopen; |
||
| 160 | $ybottom = $yclose; |
||
| 161 | } else { |
||
| 162 | $ytop = $yclose; |
||
| 163 | $ybottom = $yopen; |
||
| 164 | } |
||
| 165 | $img->SetColor($this->color); |
||
| 166 | $img->Line($xt, $ytop, $xt, $ymax); |
||
| 167 | $img->Line($xt, $ybottom, $xt, $ymin); |
||
| 168 | |||
| 169 | if ($this->iEndLines) { |
||
| 170 | $img->Line($xl, $ymax, $xr, $ymax); |
||
| 171 | $img->Line($xl, $ymin, $xr, $ymin); |
||
| 172 | } |
||
| 173 | |||
| 174 | // A chance for subclasses to add things to the bar |
||
| 175 | // for data point i |
||
| 176 | $this->ModBox($img, $xscale, $yscale, $i, $xl, $xr, $neg); |
||
| 177 | |||
| 178 | // Setup image maps |
||
| 179 | if (!empty($this->csimtargets[$i])) { |
||
| 180 | $this->csimareas .= '<area shape="rect" coords="' . |
||
| 181 | round($xl) . ',' . round($ytop) . ',' . |
||
| 182 | round($xr) . ',' . round($ybottom) . '" '; |
||
| 183 | $this->csimareas .= ' href="' . $this->csimtargets[$i] . '"'; |
||
| 184 | if (!empty($this->csimalts[$i])) { |
||
| 185 | $sval = $this->csimalts[$i]; |
||
| 186 | $this->csimareas .= " title=\"${sval}\" alt=\"${sval}\" "; |
||
| 187 | } |
||
| 188 | $this->csimareas .= " />\n"; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | return true; |
||
| 193 | } |
||
| 200 |