SetupXY::setupYAxis()   A
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 16
rs 9.2222
c 1
b 0
f 0
cc 6
nc 8
nop 2
1
<?php
2
3
namespace Ballybran\Library;
4
class SetupXY
5
{
6
7
8
    public function setupXAxis($percent = '', $color = '')
9
    {
10
        $this->bool_x_axis_setup = true;
0 ignored issues
show
Bug Best Practice introduced by
The property bool_x_axis_setup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
11
        if (false === $percent) {
12
            $this->bool_x_axis = false;
0 ignored issues
show
Bug Best Practice introduced by
The property bool_x_axis does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
13
        } else {
14
            $this->bool_x_axis = true;
15
        }
16
        if (!empty($color) && $arr = $this->returnColorArray($color)) {
17
            $this->x_axis_color = imagecolorallocate($this->image, $arr[0], $arr[1], $arr[2]);
0 ignored issues
show
Bug Best Practice introduced by
The property x_axis_color does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug Best Practice introduced by
The property image does not exist on Ballybran\Library\SetupXY. Did you maybe forget to declare it?
Loading history...
18
        }
19
        if (is_numeric($percent) && $percent > 0) {
20
            $percent = $percent / 100;
21
            $this->x_axis_margin = round($this->height * $percent);
0 ignored issues
show
Bug Best Practice introduced by
The property x_axis_margin does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug Best Practice introduced by
The property height does not exist on Ballybran\Library\SetupXY. Did you maybe forget to declare it?
Loading history...
22
        } else {
23
            $percent = self::X_AXIS_MARGIN_PERCENT / 100;
0 ignored issues
show
Bug introduced by
The constant Ballybran\Library\SetupXY::X_AXIS_MARGIN_PERCENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
24
            $this->x_axis_margin = round($this->height * $percent);
25
        }
26
    }
27
28
    public function setupYAxis($percent = '', $color = '')
29
    {
30
        $this->bool_y_axis_setup = true;
0 ignored issues
show
Bug Best Practice introduced by
The property bool_y_axis_setup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
        if (false === $percent) {
32
            $this->bool_y_axis = false;
0 ignored issues
show
Bug Best Practice introduced by
The property bool_y_axis does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
        } else {
34
            $this->bool_y_axis = true;
35
        }
36
        if (!empty($color) && $arr = $this->returnColorArray($color)) {
37
            $this->y_axis_color = imagecolorallocate($this->image, $arr[0], $arr[1], $arr[2]);
0 ignored issues
show
Bug Best Practice introduced by
The property y_axis_color does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug Best Practice introduced by
The property image does not exist on Ballybran\Library\SetupXY. Did you maybe forget to declare it?
Loading history...
38
        }
39
        if (is_numeric($percent) && $percent > 0) {
40
            $this->y_axis_margin = round($this->width * ($percent / 100));
0 ignored issues
show
Bug Best Practice introduced by
The property y_axis_margin does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug Best Practice introduced by
The property width does not exist on Ballybran\Library\SetupXY. Did you maybe forget to declare it?
Loading history...
41
        } else {
42
            $percent = self::Y_AXIS_MARGIN_PERCENT / 100;
0 ignored issues
show
Bug introduced by
The constant Ballybran\Library\SetupXY::Y_AXIS_MARGIN_PERCENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
43
            $this->y_axis_margin = round($this->width * $percent);
44
        }
45
    }
46
47
    public function setRange($min, $max)
48
    {
49
        //because of deprecated use of this function as($max, $min)
50
        if ($min > $max) {
51
            $this->data_range_max = $min;
0 ignored issues
show
Bug Best Practice introduced by
The property data_range_max does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
52
            $this->data_range_min = $max;
0 ignored issues
show
Bug Best Practice introduced by
The property data_range_min does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
53
        } else {
54
            $this->data_range_max = $max;
55
            $this->data_range_min = $min;
56
        }
57
        $this->bool_user_data_range = true;
0 ignored issues
show
Bug Best Practice introduced by
The property bool_user_data_range does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
58
    }
59
60
    protected function returnColorArray($color)
61
    {
62
        //check to see if color passed through in form '128,128,128' or hex format
63
        if (false !== strpos($color, ',')) {
64
            return explode(',', $color);
65
        } elseif ('#' == substr($color, 0, 1)) {
66
            if (strlen($color) == 7) {
67
                $hex1 = hexdec(substr($color, 1, 2));
68
                $hex2 = hexdec(substr($color, 3, 2));
69
                $hex3 = hexdec(substr($color, 5, 2));
70
                return array($hex1, $hex2, $hex3);
71
            } elseif (strlen($color) == 4) {
72
                $hex1 = hexdec(substr($color, 1, 1) . substr($color, 1, 1));
73
                $hex2 = hexdec(substr($color, 2, 1) . substr($color, 2, 1));
74
                $hex3 = hexdec(substr($color, 3, 1) . substr($color, 3, 1));
75
                return array($hex1, $hex2, $hex3);
76
            }
77
        }
78
79
        switch (strtolower($color)) {
80
            //named colors based on W3C's recd html colors
81
            case 'black':
82
                return array(0, 0, 0);
83
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
84
            case 'silver':
85
                return array(192, 192, 192);
86
                break;
87
            case 'gray':
88
                return array(128, 128, 128);
89
                break;
90
            case 'white':
91
                return array(255, 255, 255);
92
                break;
93
            case 'maroon':
94
                return array(128, 0, 0);
95
                break;
96
            case 'red':
97
                return array(255, 0, 0);
98
                break;
99
            case 'purple':
100
                return array(128, 0, 128);
101
                break;
102
            case 'fuscia':
103
                return array(255, 0, 255);
104
                break;
105
            case 'green':
106
                return array(0, 128, 0);
107
                break;
108
            case 'lime':
109
                return array(0, 255, 0);
110
                break;
111
            case 'olive':
112
                return array(128, 128, 0);
113
                break;
114
            case 'yellow':
115
                return array(255, 255, 0);
116
                break;
117
            case 'navy':
118
                return array(0, 0, 128);
119
                break;
120
            case 'blue':
121
                return array(0, 0, 255);
122
                break;
123
            case 'teal':
124
                return array(0, 128, 128);
125
                break;
126
            case 'aqua':
127
                return array(0, 255, 255);
128
                break;
129
        }
130
131
        $this->error[] = "Color name \"$color\" not recogized.";
0 ignored issues
show
Bug Best Practice introduced by
The property error does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
132
        return false;
133
    }
134
135
136
}