| Conditions | 31 |
| Paths | 103 |
| Total Lines | 176 |
| Code Lines | 149 |
| 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 |
||
| 202 | public function StrokeAngleLabels($pos, $type) |
||
| 203 | { |
||
| 204 | if (!$this->show_angle_label) { |
||
| 205 | return; |
||
| 206 | } |
||
| 207 | |||
| 208 | $x0 = round($this->img->left_margin + $this->img->plotwidth / 2) + 1; |
||
| 209 | |||
| 210 | $d = max($this->img->plotwidth, $this->img->plotheight) * 1.42; |
||
| 211 | $a = $this->angle_step; |
||
| 212 | $t = new Text\Text(); |
||
| 213 | $t->SetColor($this->angle_fontcolor); |
||
| 214 | $t->SetFont($this->angle_fontfam, $this->angle_fontstyle, $this->angle_fontsize); |
||
| 215 | $xright = $this->img->width - $this->img->right_margin; |
||
| 216 | $ytop = $this->img->top_margin; |
||
| 217 | $xleft = $this->img->left_margin; |
||
| 218 | $ybottom = $this->img->height - $this->img->bottom_margin; |
||
| 219 | $ha = 'left'; |
||
| 220 | $va = 'center'; |
||
| 221 | $w = $this->img->plotwidth / 2; |
||
| 222 | $h = $this->img->plotheight / 2; |
||
| 223 | $xt = $x0; |
||
| 224 | $yt = $pos; |
||
| 225 | $margin = 5; |
||
| 226 | |||
| 227 | $tl = $this->angle_tick_len; // Outer len |
||
| 228 | $tl2 = $this->angle_tick_len2; // Interior len |
||
| 229 | |||
| 230 | $this->img->SetColor($this->angle_tick_color); |
||
| 231 | $rot90 = $this->img->a == 90; |
||
| 232 | |||
| 233 | if ($type == POLAR_360) { |
||
| 234 | // Corner angles of the four corners |
||
| 235 | $ca1 = atan($h / $w) / M_PI * 180; |
||
| 236 | $ca2 = 180 - $ca1; |
||
| 237 | $ca3 = $ca1 + 180; |
||
| 238 | $ca4 = 360 - $ca1; |
||
| 239 | $end = 360; |
||
| 240 | |||
| 241 | while ($a < $end) { |
||
| 242 | $ca = cos($a / 180 * M_PI); |
||
| 243 | $sa = sin($a / 180 * M_PI); |
||
| 244 | $x = $d * $ca; |
||
| 245 | $y = $d * $sa; |
||
| 246 | $xt = 1000; |
||
| 247 | $yt = 1000; |
||
| 248 | if ($a <= $ca1 || $a >= $ca4) { |
||
| 249 | $yt = $pos - $w * $y / $x; |
||
| 250 | $xt = $xright + $margin; |
||
| 251 | if ($rot90) { |
||
| 252 | $ha = 'center'; |
||
| 253 | $va = 'top'; |
||
| 254 | } else { |
||
| 255 | $ha = 'left'; |
||
| 256 | $va = 'center'; |
||
| 257 | } |
||
| 258 | $x1 = $xright - $tl2; |
||
| 259 | $x2 = $xright + $tl; |
||
| 260 | $y1 = $y2 = $yt; |
||
| 261 | } elseif ($a > $ca1 && $a < $ca2) { |
||
| 262 | $xt = $x0 + $h * $x / $y; |
||
| 263 | $yt = $ytop - $margin; |
||
| 264 | if ($rot90) { |
||
| 265 | $ha = 'left'; |
||
| 266 | $va = 'center'; |
||
| 267 | } else { |
||
| 268 | $ha = 'center'; |
||
| 269 | $va = 'bottom'; |
||
| 270 | } |
||
| 271 | $y1 = $ytop + $tl2; |
||
| 272 | $y2 = $ytop - $tl; |
||
| 273 | $x1 = $x2 = $xt; |
||
| 274 | } elseif ($a >= $ca2 && $a <= $ca3) { |
||
| 275 | $yt = $pos + $w * $y / $x; |
||
| 276 | $xt = $xleft - $margin; |
||
| 277 | if ($rot90) { |
||
| 278 | $ha = 'center'; |
||
| 279 | $va = 'bottom'; |
||
| 280 | } else { |
||
| 281 | $ha = 'right'; |
||
| 282 | $va = 'center'; |
||
| 283 | } |
||
| 284 | $x1 = $xleft + $tl2; |
||
| 285 | $x2 = $xleft - $tl; |
||
| 286 | $y1 = $y2 = $yt; |
||
| 287 | } else { |
||
| 288 | $xt = $x0 - $h * $x / $y; |
||
| 289 | $yt = $ybottom + $margin; |
||
| 290 | if ($rot90) { |
||
| 291 | $ha = 'right'; |
||
| 292 | $va = 'center'; |
||
| 293 | } else { |
||
| 294 | $ha = 'center'; |
||
| 295 | $va = 'top'; |
||
| 296 | } |
||
| 297 | $y1 = $ybottom - $tl2; |
||
| 298 | $y2 = $ybottom + $tl; |
||
| 299 | $x1 = $x2 = $xt; |
||
| 300 | } |
||
| 301 | if ($a != 0 && $a != 180) { |
||
| 302 | $t->Align($ha, $va); |
||
| 303 | if ($this->scale->clockwise) { |
||
| 304 | $t->Set(360 - $a); |
||
| 305 | } else { |
||
| 306 | $t->Set($a); |
||
| 307 | } |
||
| 308 | if ($this->show_angle_mark && $t->font_family > 4) { |
||
| 309 | $a .= SymChar::Get('degree'); |
||
| 310 | } |
||
| 311 | $t->Stroke($this->img, $xt, $yt); |
||
| 312 | if ($this->show_angle_tick) { |
||
| 313 | $this->img->Line($x1, $y1, $x2, $y2); |
||
| 314 | } |
||
| 315 | } |
||
| 316 | $a += $this->angle_step; |
||
| 317 | } |
||
| 318 | } else { |
||
| 319 | // POLAR_HALF |
||
| 320 | $ca1 = atan($h / $w * 2) / M_PI * 180; |
||
| 321 | $ca2 = 180 - $ca1; |
||
| 322 | $end = 180; |
||
| 323 | while ($a < $end) { |
||
| 324 | $ca = cos($a / 180 * M_PI); |
||
| 325 | $sa = sin($a / 180 * M_PI); |
||
| 326 | $x = $d * $ca; |
||
| 327 | $y = $d * $sa; |
||
| 328 | if ($a <= $ca1) { |
||
| 329 | $yt = $pos - $w * $y / $x; |
||
| 330 | $xt = $xright + $margin; |
||
| 331 | if ($rot90) { |
||
| 332 | $ha = 'center'; |
||
| 333 | $va = 'top'; |
||
| 334 | } else { |
||
| 335 | $ha = 'left'; |
||
| 336 | $va = 'center'; |
||
| 337 | } |
||
| 338 | $x1 = $xright - $tl2; |
||
| 339 | $x2 = $xright + $tl; |
||
| 340 | $y1 = $y2 = $yt; |
||
| 341 | } elseif ($a > $ca1 && $a < $ca2) { |
||
| 342 | $xt = $x0 + 2 * $h * $x / $y; |
||
| 343 | $yt = $ytop - $margin; |
||
| 344 | if ($rot90) { |
||
| 345 | $ha = 'left'; |
||
| 346 | $va = 'center'; |
||
| 347 | } else { |
||
| 348 | $ha = 'center'; |
||
| 349 | $va = 'bottom'; |
||
| 350 | } |
||
| 351 | $y1 = $ytop + $tl2; |
||
| 352 | $y2 = $ytop - $tl; |
||
| 353 | $x1 = $x2 = $xt; |
||
| 354 | } elseif ($a >= $ca2) { |
||
| 355 | $yt = $pos + $w * $y / $x; |
||
| 356 | $xt = $xleft - $margin; |
||
| 357 | if ($rot90) { |
||
| 358 | $ha = 'center'; |
||
| 359 | $va = 'bottom'; |
||
| 360 | } else { |
||
| 361 | $ha = 'right'; |
||
| 362 | $va = 'center'; |
||
| 363 | } |
||
| 364 | $x1 = $xleft + $tl2; |
||
| 365 | $x2 = $xleft - $tl; |
||
| 366 | $y1 = $y2 = $yt; |
||
| 367 | } |
||
| 368 | $t->Align($ha, $va); |
||
| 369 | if ($this->show_angle_mark && $t->font_family > 4) { |
||
| 370 | $a .= SymChar::Get('degree'); |
||
| 371 | } |
||
| 372 | $t->Set($a); |
||
| 373 | $t->Stroke($this->img, $xt, $yt); |
||
| 374 | if ($this->show_angle_tick) { |
||
| 375 | $this->img->Line($x1, $y1, $x2, $y2); |
||
| 376 | } |
||
| 377 | $a += $this->angle_step; |
||
| 378 | } |
||
| 478 |