| Conditions | 8 |
| Paths | 32 |
| Total Lines | 58 |
| Code Lines | 38 |
| 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 |
||
| 180 | public function Stroke($img, $pos, $scale, $startangle) |
||
| 181 | { |
||
| 182 | $nbrpnts = safe_count($this->data); |
||
| 183 | $astep = 2 * M_PI / $nbrpnts; |
||
| 184 | $a = $startangle; |
||
| 185 | |||
| 186 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 187 | // Rotate each non null point to the correct axis-angle |
||
| 188 | $cs = $scale->RelTranslate($this->data[$i]); |
||
| 189 | $x = round($cs * cos($a) + $scale->scale_abs[0]); |
||
| 190 | $y = round($pos - $cs * sin($a)); |
||
| 191 | |||
| 192 | $pnts[$i * 2] = $x; |
||
| 193 | $pnts[$i * 2 + 1] = $y; |
||
| 194 | |||
| 195 | // If the next point is null then we draw this polygon segment |
||
| 196 | // to the center, skip the next and draw the next segment from |
||
| 197 | // the center up to the point on the axis with the first non-null |
||
| 198 | // value and continues from that point. Some additoinal logic is necessary |
||
| 199 | // to handle the boundary conditions |
||
| 200 | if ($i < $nbrpnts - 1) { |
||
| 201 | if (is_null($this->data[$i + 1])) { |
||
| 202 | $cs = 0; |
||
| 203 | $x = round($cs * cos($a) + $scale->scale_abs[0]); |
||
| 204 | $y = round($pos - $cs * sin($a)); |
||
| 205 | $pnts[$i * 2] = $x; |
||
| 206 | $pnts[$i * 2 + 1] = $y; |
||
| 207 | $a += $astep; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | $a += $astep; |
||
| 212 | } |
||
| 213 | |||
| 214 | if ($this->fill) { |
||
| 215 | $img->SetColor($this->fill_color); |
||
| 216 | $img->FilledPolygon($pnts); |
||
| 217 | } |
||
| 218 | |||
| 219 | $img->SetLineWeight($this->weight); |
||
| 220 | $img->SetColor($this->color); |
||
| 221 | $img->SetLineStyle($this->linestyle); |
||
| 222 | $pnts[] = $pnts[0]; |
||
| 223 | $pnts[] = $pnts[1]; |
||
| 224 | $img->Polygon($pnts); |
||
| 225 | $img->SetLineStyle('solid'); // Reset line style to default |
||
| 226 | |||
| 227 | // Add plotmarks on top |
||
| 228 | if ($this->mark->show) { |
||
| 229 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 230 | if (isset($this->csimtargets[$i])) { |
||
| 231 | $this->mark->SetCSIMTarget($this->csimtargets[$i]); |
||
| 232 | $this->mark->SetCSIMAlt($this->csimalts[$i]); |
||
| 233 | $this->mark->SetCSIMAltVal($pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 234 | $this->mark->Stroke($img, $pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 235 | $this->csimareas .= $this->mark->GetCSIMAreas(); |
||
| 236 | } else { |
||
| 237 | $this->mark->Stroke($img, $pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 238 | } |
||
| 262 |