| Conditions | 54 |
| Paths | 8242 |
| Total Lines | 309 |
| Code Lines | 240 |
| 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 |
||
| 220 | public function Stroke($img, $x, $y) |
||
| 221 | { |
||
| 222 | if (!$this->show) { |
||
| 223 | return; |
||
| 224 | } |
||
| 225 | |||
| 226 | if ($this->iFormatCallback != '' || $this->iFormatCallback2 != '') { |
||
| 227 | if ($this->iFormatCallback != '') { |
||
| 228 | $f = $this->iFormatCallback; |
||
| 229 | list($width, $color, $fcolor) = call_user_func($f, $this->yvalue); |
||
| 230 | $filename = $this->iFileName; |
||
| 231 | $imgscale = $this->iScale; |
||
| 232 | } else { |
||
| 233 | $f = $this->iFormatCallback2; |
||
| 234 | list($width, $color, $fcolor, $filename, $imgscale) = call_user_func($f, $this->yvalue, $this->xvalue); |
||
| 235 | if ($filename == '') { |
||
| 236 | $filename = $this->iFileName; |
||
| 237 | } |
||
| 238 | |||
| 239 | if ($imgscale == '') { |
||
| 240 | $imgscale = $this->iScale; |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | if ($width == '') { |
||
| 245 | $width = $this->width; |
||
| 246 | } |
||
| 247 | |||
| 248 | if ($color == '') { |
||
| 249 | $color = $this->color; |
||
| 250 | } |
||
| 251 | |||
| 252 | if ($fcolor == '') { |
||
| 253 | $fcolor = $this->fill_color; |
||
| 254 | } |
||
| 255 | } else { |
||
| 256 | $fcolor = $this->fill_color; |
||
| 257 | $color = $this->color; |
||
| 258 | $width = $this->width; |
||
| 259 | $filename = $this->iFileName; |
||
| 260 | $imgscale = $this->iScale; |
||
| 261 | } |
||
| 262 | |||
| 263 | if ($this->type == MARK_IMG || |
||
| 264 | ($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4) || |
||
| 265 | $this->type >= MARK_IMG_PUSHPIN) { |
||
| 266 | // Note: For the builtin images we use the "filename" parameter |
||
| 267 | // to denote the color |
||
| 268 | $anchor_x = 0.5; |
||
| 269 | $anchor_y = 0.5; |
||
| 270 | switch ($this->type) { |
||
| 271 | case MARK_FLAG1: |
||
| 272 | case MARK_FLAG2: |
||
| 273 | case MARK_FLAG3: |
||
| 274 | case MARK_FLAG4: |
||
| 275 | $this->markimg = Util\FlagCache::GetFlagImgByName($this->type - MARK_FLAG1 + 1, $filename); |
||
| 276 | |||
| 277 | break; |
||
| 278 | case MARK_IMG: |
||
| 279 | // Load an image and use that as a marker |
||
| 280 | // Small optimization, if we have already read an image don't |
||
| 281 | // waste time reading it again. |
||
| 282 | if ($this->markimg == '' || !($this->oldfilename === $filename)) { |
||
| 283 | $this->markimg = Graph\Graph::LoadBkgImage('', $filename); |
||
| 284 | $this->oldfilename = $filename; |
||
| 285 | } |
||
| 286 | |||
| 287 | break; |
||
| 288 | case MARK_IMG_PUSHPIN: |
||
| 289 | case MARK_IMG_SPUSHPIN: |
||
| 290 | case MARK_IMG_LPUSHPIN: |
||
| 291 | if ($this->imgdata_pushpins == null) { |
||
| 292 | $this->imgdata_pushpins = new Image\ImgData_PushPins(); |
||
| 293 | } |
||
| 294 | $this->markimg = $this->imgdata_pushpins->GetImg($this->type, $filename); |
||
| 295 | list($anchor_x, $anchor_y) = $this->imgdata_pushpins->GetAnchor(); |
||
| 296 | |||
| 297 | break; |
||
| 298 | case MARK_IMG_SQUARE: |
||
| 299 | if ($this->imgdata_squares == null) { |
||
| 300 | $this->imgdata_squares = new Image\ImgData_Squares(); |
||
| 301 | } |
||
| 302 | $this->markimg = $this->imgdata_squares->GetImg($this->type, $filename); |
||
| 303 | list($anchor_x, $anchor_y) = $this->imgdata_squares->GetAnchor(); |
||
| 304 | |||
| 305 | break; |
||
| 306 | case MARK_IMG_STAR: |
||
| 307 | if ($this->imgdata_stars == null) { |
||
| 308 | $this->imgdata_stars = new Image\ImgData_Stars(); |
||
| 309 | } |
||
| 310 | $this->markimg = $this->imgdata_stars->GetImg($this->type, $filename); |
||
| 311 | list($anchor_x, $anchor_y) = $this->imgdata_stars->GetAnchor(); |
||
| 312 | |||
| 313 | break; |
||
| 314 | case MARK_IMG_BEVEL: |
||
| 315 | if ($this->imgdata_bevels == null) { |
||
| 316 | $this->imgdata_bevels = new Image\ImgData_Bevels(); |
||
| 317 | } |
||
| 318 | $this->markimg = $this->imgdata_bevels->GetImg($this->type, $filename); |
||
| 319 | list($anchor_x, $anchor_y) = $this->imgdata_bevels->GetAnchor(); |
||
| 320 | |||
| 321 | break; |
||
| 322 | case MARK_IMG_DIAMOND: |
||
| 323 | if ($this->imgdata_diamonds == null) { |
||
| 324 | $this->imgdata_diamonds = new Image\ImgData_Diamonds(); |
||
| 325 | } |
||
| 326 | $this->markimg = $this->imgdata_diamonds->GetImg($this->type, $filename); |
||
| 327 | list($anchor_x, $anchor_y) = $this->imgdata_diamonds->GetAnchor(); |
||
| 328 | |||
| 329 | break; |
||
| 330 | case MARK_IMG_BALL: |
||
| 331 | case MARK_IMG_SBALL: |
||
| 332 | case MARK_IMG_MBALL: |
||
| 333 | case MARK_IMG_LBALL: |
||
| 334 | if ($this->imgdata_balls == null) { |
||
| 335 | $this->imgdata_balls = new Image\ImgData_Balls(); |
||
| 336 | } |
||
| 337 | $this->markimg = $this->imgdata_balls->GetImg($this->type, $filename); |
||
| 338 | list($anchor_x, $anchor_y) = $this->imgdata_balls->GetAnchor(); |
||
| 339 | |||
| 340 | break; |
||
| 341 | } |
||
| 342 | |||
| 343 | $w = $img->GetWidth($this->markimg); |
||
| 344 | $h = $img->GetHeight($this->markimg); |
||
| 345 | |||
| 346 | $dw = round($imgscale * $w); |
||
| 347 | $dh = round($imgscale * $h); |
||
| 348 | |||
| 349 | // Do potential rotation |
||
| 350 | list($x, $y) = $img->Rotate($x, $y); |
||
| 351 | |||
| 352 | $dx = round($x - $dw * $anchor_x); |
||
| 353 | $dy = round($y - $dh * $anchor_y); |
||
| 354 | |||
| 355 | $this->width = max($dx, $dy); |
||
| 356 | |||
| 357 | $img->Copy($this->markimg, $dx, $dy, 0, 0, $dw, $dh, $w, $h); |
||
| 358 | if (!empty($this->csimtarget)) { |
||
| 359 | $this->csimareas = '<area shape="rect" coords="' . |
||
| 360 | $dx . ',' . $dy . ',' . round($dx + $dw) . ',' . round($dy + $dh) . '" ' . |
||
| 361 | 'href="' . htmlentities($this->csimtarget) . '"'; |
||
| 362 | |||
| 363 | if (!empty($this->csimwintarget)) { |
||
| 364 | $this->csimareas .= ' target="' . $this->csimwintarget . '" '; |
||
| 365 | } |
||
| 366 | |||
| 367 | if (!empty($this->csimalt)) { |
||
| 368 | $tmp = sprintf($this->csimalt, $this->yvalue, $this->xvalue); |
||
| 369 | $this->csimareas .= " title=\"${tmp}\" alt=\"${tmp}\" "; |
||
| 370 | } |
||
| 371 | $this->csimareas .= " />\n"; |
||
| 372 | } |
||
| 373 | |||
| 374 | // Stroke title |
||
| 375 | $this->title->Align('center', 'top'); |
||
| 376 | $this->title->Stroke($img, $x, $y + round($dh / 2)); |
||
| 377 | |||
| 378 | return; |
||
| 379 | } |
||
| 380 | |||
| 381 | $weight = $this->weight; |
||
| 382 | $dx = round($width / 2, 0); |
||
| 383 | $dy = round($width / 2, 0); |
||
| 384 | $pts = 0; |
||
| 385 | |||
| 386 | switch ($this->type) { |
||
| 387 | case MARK_SQUARE: |
||
| 388 | $c[] = $x - $dx; |
||
|
|
|||
| 389 | $c[] = $y - $dy; |
||
| 390 | $c[] = $x + $dx; |
||
| 391 | $c[] = $y - $dy; |
||
| 392 | $c[] = $x + $dx; |
||
| 393 | $c[] = $y + $dy; |
||
| 394 | $c[] = $x - $dx; |
||
| 395 | $c[] = $y + $dy; |
||
| 396 | $c[] = $x - $dx; |
||
| 397 | $c[] = $y - $dy; |
||
| 398 | $pts = 5; |
||
| 399 | |||
| 400 | break; |
||
| 401 | case MARK_UTRIANGLE: |
||
| 402 | ++$dx; ++$dy; |
||
| 403 | $c[] = $x - $dx; |
||
| 404 | $c[] = $y + 0.87 * $dy; // tan(60)/2*$dx |
||
| 405 | $c[] = $x; |
||
| 406 | $c[] = $y - 0.87 * $dy; |
||
| 407 | $c[] = $x + $dx; |
||
| 408 | $c[] = $y + 0.87 * $dy; |
||
| 409 | $c[] = $x - $dx; |
||
| 410 | $c[] = $y + 0.87 * $dy; // tan(60)/2*$dx |
||
| 411 | $pts = 4; |
||
| 412 | |||
| 413 | break; |
||
| 414 | case MARK_DTRIANGLE: |
||
| 415 | ++$dx; ++$dy; |
||
| 416 | $c[] = $x; |
||
| 417 | $c[] = $y + 0.87 * $dy; // tan(60)/2*$dx |
||
| 418 | $c[] = $x - $dx; |
||
| 419 | $c[] = $y - 0.87 * $dy; |
||
| 420 | $c[] = $x + $dx; |
||
| 421 | $c[] = $y - 0.87 * $dy; |
||
| 422 | $c[] = $x; |
||
| 423 | $c[] = $y + 0.87 * $dy; // tan(60)/2*$dx |
||
| 424 | $pts = 4; |
||
| 425 | |||
| 426 | break; |
||
| 427 | case MARK_DIAMOND: |
||
| 428 | $c[] = $x; |
||
| 429 | $c[] = $y + $dy; |
||
| 430 | $c[] = $x - $dx; |
||
| 431 | $c[] = $y; |
||
| 432 | $c[] = $x; |
||
| 433 | $c[] = $y - $dy; |
||
| 434 | $c[] = $x + $dx; |
||
| 435 | $c[] = $y; |
||
| 436 | $c[] = $x; |
||
| 437 | $c[] = $y + $dy; |
||
| 438 | $pts = 5; |
||
| 439 | |||
| 440 | break; |
||
| 441 | case MARK_LEFTTRIANGLE: |
||
| 442 | $c[] = $x; |
||
| 443 | $c[] = $y; |
||
| 444 | $c[] = $x; |
||
| 445 | $c[] = $y + 2 * $dy; |
||
| 446 | $c[] = $x + $dx * 2; |
||
| 447 | $c[] = $y; |
||
| 448 | $c[] = $x; |
||
| 449 | $c[] = $y; |
||
| 450 | $pts = 4; |
||
| 451 | |||
| 452 | break; |
||
| 453 | case MARK_RIGHTTRIANGLE: |
||
| 454 | $c[] = $x - $dx * 2; |
||
| 455 | $c[] = $y; |
||
| 456 | $c[] = $x; |
||
| 457 | $c[] = $y + 2 * $dy; |
||
| 458 | $c[] = $x; |
||
| 459 | $c[] = $y; |
||
| 460 | $c[] = $x - $dx * 2; |
||
| 461 | $c[] = $y; |
||
| 462 | $pts = 4; |
||
| 463 | |||
| 464 | break; |
||
| 465 | case MARK_FLASH: |
||
| 466 | $dy *= 2; |
||
| 467 | $c[] = $x + $dx / 2; |
||
| 468 | $c[] = $y - $dy; |
||
| 469 | $c[] = $x - $dx + $dx / 2; |
||
| 470 | $c[] = $y + $dy * 0.7 - $dy; |
||
| 471 | $c[] = $x + $dx / 2; |
||
| 472 | $c[] = $y + $dy * 1.3 - $dy; |
||
| 473 | $c[] = $x - $dx + $dx / 2; |
||
| 474 | $c[] = $y + 2 * $dy - $dy; |
||
| 475 | $img->SetLineWeight($weight); |
||
| 476 | $img->SetColor($color); |
||
| 477 | $img->Polygon($c); |
||
| 478 | $img->SetLineWeight(1); |
||
| 479 | $this->AddCSIMPoly($c); |
||
| 480 | |||
| 481 | break; |
||
| 482 | } |
||
| 483 | |||
| 484 | if ($pts > 0) { |
||
| 485 | $this->AddCSIMPoly($c); |
||
| 486 | $img->SetLineWeight($weight); |
||
| 487 | $img->SetColor($fcolor); |
||
| 488 | $img->FilledPolygon($c); |
||
| 489 | $img->SetColor($color); |
||
| 490 | $img->Polygon($c); |
||
| 491 | $img->SetLineWeight(1); |
||
| 492 | } elseif ($this->type == MARK_CIRCLE) { |
||
| 493 | $img->SetColor($color); |
||
| 494 | $img->Circle($x, $y, $width); |
||
| 495 | $this->AddCSIMCircle($x, $y, $width); |
||
| 496 | } elseif ($this->type == MARK_FILLEDCIRCLE) { |
||
| 497 | $img->SetColor($fcolor); |
||
| 498 | $img->FilledCircle($x, $y, $width); |
||
| 499 | $img->SetColor($color); |
||
| 500 | $img->Circle($x, $y, $width); |
||
| 501 | $this->AddCSIMCircle($x, $y, $width); |
||
| 502 | } elseif ($this->type == MARK_CROSS) { |
||
| 503 | // Oversize by a pixel to match the X |
||
| 504 | $img->SetColor($color); |
||
| 505 | $img->SetLineWeight($weight); |
||
| 506 | $img->Line($x, $y + $dy + 1, $x, $y - $dy - 1); |
||
| 507 | $img->Line($x - $dx - 1, $y, $x + $dx + 1, $y); |
||
| 508 | $this->AddCSIMCircle($x, $y, $dx); |
||
| 509 | } elseif ($this->type == MARK_X) { |
||
| 510 | $img->SetColor($color); |
||
| 511 | $img->SetLineWeight($weight); |
||
| 512 | $img->Line($x + $dx, $y + $dy, $x - $dx, $y - $dy); |
||
| 513 | $img->Line($x - $dx, $y + $dy, $x + $dx, $y - $dy); |
||
| 514 | $this->AddCSIMCircle($x, $y, $dx + $dy); |
||
| 515 | } elseif ($this->type == MARK_STAR) { |
||
| 516 | $img->SetColor($color); |
||
| 517 | $img->SetLineWeight($weight); |
||
| 518 | $img->Line($x + $dx, $y + $dy, $x - $dx, $y - $dy); |
||
| 519 | $img->Line($x - $dx, $y + $dy, $x + $dx, $y - $dy); |
||
| 520 | // Oversize by a pixel to match the X |
||
| 521 | $img->Line($x, $y + $dy + 1, $x, $y - $dy - 1); |
||
| 522 | $img->Line($x - $dx - 1, $y, $x + $dx + 1, $y); |
||
| 523 | $this->AddCSIMCircle($x, $y, $dx + $dy); |
||
| 524 | } |
||
| 525 | |||
| 526 | // Stroke title |
||
| 527 | $this->title->Align('center', 'center'); |
||
| 528 | $this->title->Stroke($img, $x, $y); |
||
| 529 | } |
||
| 531 |