Conditions | 60 |
Paths | > 20000 |
Total Lines | 262 |
Code Lines | 181 |
Lines | 34 |
Ratio | 12.98 % |
Changes | 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 |
||
205 | public function Stroke($img, $xscale, $yscale) |
||
206 | { |
||
207 | $idx = 0; |
||
208 | $numpoints = count($this->coords[0]); |
||
209 | View Code Duplication | if (isset($this->coords[1])) { |
|
210 | if (count($this->coords[1]) != $numpoints) { |
||
211 | Util\JpGraphError::RaiseL(2003, count($this->coords[1]), $numpoints); |
||
212 | //("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints"); |
||
1 ignored issue
–
show
|
|||
213 | } else { |
||
214 | $exist_x = true; |
||
215 | } |
||
216 | } else { |
||
217 | $exist_x = false; |
||
218 | } |
||
219 | |||
220 | if ($this->barcenter) { |
||
221 | $textadj = 0.5 - $xscale->text_scale_off; |
||
222 | } else { |
||
223 | $textadj = 0; |
||
224 | } |
||
225 | |||
226 | // Find the first numeric data point |
||
227 | $startpoint = 0; |
||
228 | while ($startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint])) { |
||
229 | ++$startpoint; |
||
230 | } |
||
231 | |||
232 | // Bail out if no data points |
||
233 | if ($startpoint == $numpoints) { |
||
234 | return; |
||
235 | } |
||
236 | |||
237 | if ($this->iFastStroke) { |
||
238 | $this->FastStroke($img, $xscale, $yscale, $startpoint, $exist_x); |
||
239 | return; |
||
240 | } |
||
241 | |||
242 | if ($exist_x) { |
||
243 | $xs = $this->coords[1][$startpoint]; |
||
244 | } else { |
||
245 | $xs = $textadj + $startpoint; |
||
246 | } |
||
247 | |||
248 | $img->SetStartPoint($xscale->Translate($xs), |
||
249 | $yscale->Translate($this->coords[0][$startpoint])); |
||
250 | |||
251 | if ($this->filled) { |
||
252 | if ($this->fillFromMax) { |
||
253 | //$max = $yscale->GetMaxVal(); |
||
1 ignored issue
–
show
|
|||
254 | $cord[$idx++] = $xscale->Translate($xs); |
||
255 | $cord[$idx++] = $yscale->scale_abs[1]; |
||
256 | } else { |
||
257 | $min = $yscale->GetMinVal(); |
||
258 | if ($min > 0 || $this->fillFromMin) { |
||
259 | $fillmin = $yscale->scale_abs[0]; //Translate($min); |
||
260 | } else { |
||
261 | $fillmin = $yscale->Translate(0); |
||
262 | } |
||
263 | |||
264 | $cord[$idx++] = $xscale->Translate($xs); |
||
265 | $cord[$idx++] = $fillmin; |
||
266 | } |
||
267 | } |
||
268 | $xt = $xscale->Translate($xs); |
||
269 | $yt = $yscale->Translate($this->coords[0][$startpoint]); |
||
270 | $cord[$idx++] = $xt; |
||
271 | $cord[$idx++] = $yt; |
||
272 | $yt_old = $yt; |
||
273 | $xt_old = $xt; |
||
274 | $y_old = $this->coords[0][$startpoint]; |
||
275 | |||
276 | $this->value->Stroke($img, $this->coords[0][$startpoint], $xt, $yt); |
||
277 | |||
278 | $img->SetColor($this->color); |
||
279 | $img->SetLineWeight($this->weight); |
||
280 | $img->SetLineStyle($this->line_style); |
||
281 | $pnts = $startpoint + 1; |
||
282 | $firstnonumeric = false; |
||
283 | |||
284 | while ($pnts < $numpoints) { |
||
285 | View Code Duplication | if ($exist_x) { |
|
286 | $x = $this->coords[1][$pnts]; |
||
287 | } else { |
||
288 | $x = $pnts + $textadj; |
||
289 | } |
||
290 | $xt = $xscale->Translate($x); |
||
291 | $yt = $yscale->Translate($this->coords[0][$pnts]); |
||
292 | |||
293 | $y = $this->coords[0][$pnts]; |
||
294 | if ($this->step_style) { |
||
295 | // To handle null values within step style we need to record the |
||
296 | // first non numeric value so we know from where to start if the |
||
297 | // non value is '-'. |
||
298 | if (is_numeric($y)) { |
||
299 | $firstnonumeric = false; |
||
300 | if (is_numeric($y_old)) { |
||
301 | $img->StyleLine($xt_old, $yt_old, $xt, $yt_old); |
||
302 | $img->StyleLine($xt, $yt_old, $xt, $yt); |
||
303 | } elseif ($y_old == '-') { |
||
304 | $img->StyleLine($xt_first, $yt_first, $xt, $yt_first); |
||
305 | $img->StyleLine($xt, $yt_first, $xt, $yt); |
||
306 | } else { |
||
307 | $yt_old = $yt; |
||
308 | $xt_old = $xt; |
||
309 | } |
||
310 | $cord[$idx++] = $xt; |
||
311 | $cord[$idx++] = $yt_old; |
||
312 | $cord[$idx++] = $xt; |
||
313 | $cord[$idx++] = $yt; |
||
314 | } elseif ($firstnonumeric == false) { |
||
315 | $firstnonumeric = true; |
||
316 | $yt_first = $yt_old; |
||
317 | $xt_first = $xt_old; |
||
318 | } |
||
319 | } else { |
||
320 | $tmp1 = $y; |
||
321 | $prev = $this->coords[0][$pnts - 1]; |
||
322 | View Code Duplication | if ($tmp1 === '' || $tmp1 === null || $tmp1 === 'X') { |
|
323 | $tmp1 = 'x'; |
||
324 | } |
||
325 | |||
326 | View Code Duplication | if ($prev === '' || $prev === null || $prev === 'X') { |
|
327 | $prev = 'x'; |
||
328 | } |
||
329 | |||
330 | if (is_numeric($y) || (is_string($y) && $y != '-')) { |
||
331 | if (is_numeric($y) && (is_numeric($prev) || $prev === '-')) { |
||
332 | $img->StyleLineTo($xt, $yt); |
||
333 | } else { |
||
334 | $img->SetStartPoint($xt, $yt); |
||
335 | } |
||
336 | } |
||
337 | if ($this->filled && $tmp1 !== '-') { |
||
338 | if ($tmp1 === 'x') { |
||
339 | $cord[$idx++] = $cord[$idx - 3]; |
||
340 | $cord[$idx++] = $fillmin; |
||
341 | } elseif ($prev === 'x') { |
||
342 | $cord[$idx++] = $xt; |
||
343 | $cord[$idx++] = $fillmin; |
||
344 | $cord[$idx++] = $xt; |
||
345 | $cord[$idx++] = $yt; |
||
346 | } else { |
||
347 | $cord[$idx++] = $xt; |
||
348 | $cord[$idx++] = $yt; |
||
349 | } |
||
350 | } else { |
||
351 | if (is_numeric($tmp1) && (is_numeric($prev) || $prev === '-')) { |
||
352 | $cord[$idx++] = $xt; |
||
353 | $cord[$idx++] = $yt; |
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | $yt_old = $yt; |
||
358 | $xt_old = $xt; |
||
359 | $y_old = $y; |
||
360 | |||
361 | $this->StrokeDataValue($img, $this->coords[0][$pnts], $xt, $yt); |
||
362 | |||
363 | ++$pnts; |
||
364 | } |
||
365 | |||
366 | if ($this->filled) { |
||
367 | $cord[$idx++] = $xt; |
||
368 | if ($this->fillFromMax) { |
||
369 | $cord[$idx++] = $yscale->scale_abs[1]; |
||
370 | } else { |
||
371 | if ($min > 0 || $this->fillFromMin) { |
||
372 | $cord[$idx++] = $yscale->Translate($min); |
||
373 | } else { |
||
374 | $cord[$idx++] = $yscale->Translate(0); |
||
375 | } |
||
376 | } |
||
377 | if ($this->fillgrad) { |
||
378 | $img->SetLineWeight(1); |
||
379 | $grad = new Gradient($img); |
||
380 | $grad->SetNumColors($this->fillgrad_numcolors); |
||
381 | $grad->FilledFlatPolygon($cord, $this->fillgrad_fromcolor, $this->fillgrad_tocolor); |
||
382 | $img->SetLineWeight($this->weight); |
||
383 | } else { |
||
384 | $img->SetColor($this->fill_color); |
||
385 | $img->FilledPolygon($cord); |
||
386 | } |
||
387 | if ($this->weight > 0) { |
||
388 | $img->SetLineWeight($this->weight); |
||
389 | $img->SetColor($this->color); |
||
390 | // Remove first and last coordinate before drawing the line |
||
391 | // sine we otherwise get the vertical start and end lines which |
||
392 | // doesn't look appropriate |
||
393 | $img->Polygon(array_slice($cord, 2, count($cord) - 4)); |
||
394 | } |
||
395 | } |
||
396 | |||
397 | if (!empty($this->filledAreas)) { |
||
398 | $minY = $yscale->Translate($yscale->GetMinVal()); |
||
399 | $factor = ($this->step_style ? 4 : 2); |
||
400 | |||
401 | for ($i = 0; $i < sizeof($this->filledAreas); ++$i) { |
||
402 | // go through all filled area elements ordered by insertion |
||
403 | // fill polygon array |
||
404 | $areaCoords[] = $cord[$this->filledAreas[$i][0] * $factor]; |
||
405 | $areaCoords[] = $minY; |
||
406 | |||
407 | $areaCoords = |
||
408 | array_merge($areaCoords, |
||
409 | array_slice($cord, |
||
410 | $this->filledAreas[$i][0] * $factor, |
||
411 | ($this->filledAreas[$i][1] - $this->filledAreas[$i][0] + ($this->step_style ? 0 : 1)) * $factor)); |
||
412 | $areaCoords[] = $areaCoords[sizeof($areaCoords) - 2]; // last x |
||
413 | $areaCoords[] = $minY; // last y |
||
414 | |||
415 | if ($this->filledAreas[$i][3]) { |
||
416 | $img->SetColor($this->filledAreas[$i][2]); |
||
417 | $img->FilledPolygon($areaCoords); |
||
418 | $img->SetColor($this->color); |
||
419 | } |
||
420 | // Check if we should draw the frame. |
||
421 | // If not we still re-draw the line since it might have been |
||
422 | // partially overwritten by the filled area and it doesn't look |
||
423 | // very good. |
||
424 | if ($this->filledAreas[$i][4]) { |
||
425 | $img->Polygon($areaCoords); |
||
426 | } else { |
||
427 | $img->Polygon($cord); |
||
428 | } |
||
429 | |||
430 | $areaCoords = array(); |
||
431 | } |
||
432 | } |
||
433 | |||
434 | if (!is_object($this->mark) || $this->mark->type == -1 || $this->mark->show == false) { |
||
435 | return; |
||
436 | } |
||
437 | |||
438 | for ($pnts = 0; $pnts < $numpoints; ++$pnts) { |
||
439 | View Code Duplication | if ($exist_x) { |
|
440 | $x = $this->coords[1][$pnts]; |
||
441 | } else { |
||
442 | $x = $pnts + $textadj; |
||
443 | } |
||
444 | $xt = $xscale->Translate($x); |
||
445 | $yt = $yscale->Translate($this->coords[0][$pnts]); |
||
446 | |||
447 | if (is_numeric($this->coords[0][$pnts])) { |
||
448 | View Code Duplication | if (!empty($this->csimtargets[$pnts])) { |
|
449 | if (!empty($this->csimwintargets[$pnts])) { |
||
450 | $this->mark->SetCSIMTarget($this->csimtargets[$pnts], $this->csimwintargets[$pnts]); |
||
451 | } else { |
||
452 | $this->mark->SetCSIMTarget($this->csimtargets[$pnts]); |
||
453 | } |
||
454 | $this->mark->SetCSIMAlt($this->csimalts[$pnts]); |
||
455 | } |
||
456 | if ($exist_x) { |
||
457 | $x = $this->coords[1][$pnts]; |
||
458 | } else { |
||
459 | $x = $pnts; |
||
460 | } |
||
461 | $this->mark->SetCSIMAltVal($this->coords[0][$pnts], $x); |
||
462 | $this->mark->Stroke($img, $xt, $yt); |
||
463 | $this->csimareas .= $this->mark->GetCSIMAreas(); |
||
464 | } |
||
465 | } |
||
466 | } |
||
467 | } // Class |
||
468 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.