Passed
Push — master ( 3dc74f...81d6e9 )
by Felipe
04:17
created

ErrorPlot   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 94.59%

Importance

Changes 0
Metric Value
dl 0
loc 73
ccs 35
cts 37
cp 0.9459
rs 10
c 0
b 0
f 0
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A PreStrokeAdjust() 0 12 2
C Stroke() 0 40 8
1
<?php
2
3
/**
4
 * JPGraph v3.6.15
5
 */
6
7
namespace Amenadiel\JpGraph\Plot;
8
9
/**
10
 * File:        JPGRAPH_ERROR.PHP
11
 * // Description: Error plot extension for JpGraph
12
 * // Created:     2001-01-08
13
 * // Ver:         $Id: jpgraph_error.php 1106 2009-02-22 20:16:35Z ljp $
14
 * //
15
 * // Copyright (c) Asial Corporation. All rights reserved.
16
 */
17
18
/**
19
 * @class ErrorPlot
20
 * // Description: Error plot with min/max value for
21
 * // each datapoint
22
 */
23
class ErrorPlot extends Plot
24
{
25
    private $errwidth = 2;
26
27
    /**
28
     * CONSTRUCTOR
29
     */
30 2
    public function __construct($datay, $datax = false)
31
    {
32 2
        parent::__construct($datay, $datax);
33 2
        $this->numpoints /= 2;
34 2
    }
35
36
    /**
37
     * PUBLIC METHODS
38
     */
39
    // Gets called before any axis are stroked
40 2
    public function PreStrokeAdjust($graph)
41
    {
42 2
        if ($this->center) {
43 1
            $a = 0.5;
44 1
            $b = 0.5;
45 1
            ++$this->numpoints;
46
        } else {
47 2
            $a = 0;
48 2
            $b = 0;
49
        }
50 2
        $graph->xaxis->scale->ticks->SetXLabelOffset($a);
51 2
        $graph->SetTextScaleOff($b);
52
        //$graph->xaxis->scale->ticks->SupressMinorTickMarks();
53 2
    }
54
55
    // Method description
56 2
    public function Stroke($img, $xscale, $yscale)
57
    {
58 2
        $numpoints = count($this->coords[0]) / 2;
59 2
        $img->SetColor($this->color);
60 2
        $img->SetLineWeight($this->weight);
61
62 2
        if (isset($this->coords[1])) {
63 1
            if (count($this->coords[1]) != $numpoints) {
64
                Util\JpGraphError::RaiseL(2003, count($this->coords[1]), $numpoints);
1 ignored issue
show
Bug introduced by
The type Amenadiel\JpGraph\Plot\Util\JpGraphError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
65
            }
66
67
            //("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
68
            else {
69 1
                $exist_x = true;
70
            }
71
        } else {
72 1
            $exist_x = false;
73
        }
74
75 2
        for ($i = 0; $i < $numpoints; ++$i) {
76 2
            if ($exist_x) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $exist_x does not seem to be defined for all execution paths leading up to this point.
Loading history...
77 1
                $x = $this->coords[1][$i];
78
            } else {
79 1
                $x = $i;
80
            }
81
82 2
            if (!is_numeric($x) ||
83 2
                !is_numeric($this->coords[0][$i * 2]) || !is_numeric($this->coords[0][$i * 2 + 1])) {
84
                continue;
85
            }
86
87 2
            $xt  = $xscale->Translate($x);
88 2
            $yt1 = $yscale->Translate($this->coords[0][$i * 2]);
89 2
            $yt2 = $yscale->Translate($this->coords[0][$i * 2 + 1]);
90 2
            $img->Line($xt, $yt1, $xt, $yt2);
91 2
            $img->Line($xt - $this->errwidth, $yt1, $xt + $this->errwidth, $yt1);
92 2
            $img->Line($xt - $this->errwidth, $yt2, $xt + $this->errwidth, $yt2);
93
        }
94
95 2
        return true;
96
    }
97
} // @class
98