Passed
Pull Request — master (#22)
by
unknown
03:53
created

UniversalTheme::ApplyPlot()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 58
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 32
c 1
b 0
f 0
nc 10
nop 1
dl 0
loc 58
rs 6.6515

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
namespace Amenadiel\JpGraph\Themes;
3
4
/**
5
 * Universal Theme class
6
 */
7
class UniversalTheme extends Theme
8
{
9
    private $font_color       = '#444444';
10
    private $background_color = '#F4F4F4';
11
    private $axis_color       = '#888888';
12
    private $grid_color       = '#E3E3E3';
13
14
    public function GetColorList()
15
    {
16
        return array(
17
            '#61a9f3', #blue
18
            '#f381b9', #red
19
            '#61E3A9', #green
20
21
            #'#D56DE2',
22
            '#85eD82',
23
            '#F7b7b7',
24
            '#CFDF49',
25
            '#88d8f2',
26
            '#07AF7B',
27
            '#B9E3F9',
28
            '#FFF3AD',
29
            '#EF606A',
30
            '#EC8833',
31
            '#FFF100',
32
            '#87C9A5',
33
        );
34
    }
35
36
    public function SetupGraph($graph)
37
    {
38
39
        // graph
40
        /*
1 ignored issue
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
41
        $img = $graph->img;
42
        $height = $img->height;
43
        $graph->SetMargin($img->left_margin, $img->right_margin, $img->top_margin, $height * 0.25);
44
         */
45
        $graph->SetFrame(false);
46
        $graph->SetMarginColor('white');
47
        $graph->SetBox(true, '#DADADA');
48
        //        $graph->SetBackgroundGradient($this->background_color, '#FFFFFF', GRAD_HOR, BGRAD_PLOT);
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
49
50
        // legend
51
        $graph->legend->SetFrameWeight(0);
52
        $graph->legend->Pos(0.5, 0.85, 'center', 'top');
53
        $graph->legend->SetFillColor('white');
54
        $graph->legend->SetLayout(LEGEND_HOR);
55
        $graph->legend->SetColumns(3);
56
        $graph->legend->SetShadow(false);
57
        $graph->legend->SetMarkAbsSize(5);
58
59
        // xaxis
60
        $graph->xaxis->title->SetColor($this->font_color);
61
        $graph->xaxis->SetColor($this->axis_color, $this->font_color);
62
        $graph->xaxis->SetTickSide(SIDE_BOTTOM);
63
        $graph->xaxis->SetLabelMargin(10);
64
        $graph->xaxis->HideTicks();
65
        $graph->xaxis->SetTitleMargin(15);
66
        //$graph->xaxis->SetLabelMargin(30);
1 ignored issue
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
67
68
        // yaxis
69
        $graph->yaxis->title->SetColor($this->font_color);
70
        $graph->yaxis->SetColor($this->axis_color, $this->font_color);
71
        $graph->yaxis->SetTickSide(SIDE_LEFT);
72
        $graph->yaxis->SetLabelMargin(8);
73
        //        $graph->yaxis->SetTickPositions(array(50, 100, 150));
1 ignored issue
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
74
        //        $graph->yaxis->HideLine();
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
75
        $graph->yaxis->HideTicks();
76
77
        // grid
78
        $graph->ygrid->SetColor($this->grid_color);
79
        $graph->ygrid->SetFill(true, '#FFFFFF', $this->background_color);
80
        //       $graph->ygrid->SetLineStyle('dotted');
1 ignored issue
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
81
82
        // font
83
        $graph->title->SetColor($this->font_color);
84
        $graph->subtitle->SetColor($this->font_color);
85
        $graph->subsubtitle->SetColor($this->font_color);
86
87
        $graph->img->SetAntiAliasing();
88
    }
89
90
    public function SetupPieGraph($graph)
91
    {
92
93
        // graph
94
        $graph->SetFrame(false);
95
96
        // legend
97
        $graph->legend->SetFillColor('white');
98
99
        $graph->legend->SetFrameWeight(0);
100
        $graph->legend->Pos(0.5, 0.80, 'center', 'top');
101
        $graph->legend->SetLayout(LEGEND_HOR);
102
        $graph->legend->SetColumns(4);
103
104
        $graph->legend->SetShadow(false);
105
        $graph->legend->SetMarkAbsSize(5);
106
107
        // title
108
        $graph->title->SetColor($this->font_color);
109
        $graph->subtitle->SetColor($this->font_color);
110
        $graph->subsubtitle->SetColor($this->font_color);
111
112
        $graph->SetAntiAliasing();
113
    }
114
115 View Code Duplication
    public function PreStrokeApply($graph)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        if ($graph->legend->HasItems()) {
118
            $img    = $graph->img;
119
            $height = $img->height;
120
            $graph->SetMargin(
121
                $img->raw_left_margin,
122
                $img->raw_right_margin,
123
                $img->raw_top_margin,
124
                $height * 0.25
125
            );
126
        }
127
    }
128
129
    public function ApplyPlot($plot)
130
    {
131
        switch (get_class($plot)) {
132
            case 'GroupBarPlot':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
133
                {
134
                    foreach ($plot->plots as $_plot) {
135
                        $this->ApplyPlot($_plot);
136
                    }
137
                    break;
138
                }
139
140
            case 'AccBarPlot':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
141
                {
142
                    foreach ($plot->plots as $_plot) {
143
                        $this->ApplyPlot($_plot);
144
                    }
145
                    break;
146
                }
147
148
            case 'BarPlot':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
149
                {
150
                    if(!$plot->fill){
151
                        $plot->Clear();
152
                        $color = $this->GetNextColor();
153
                        $plot->SetColor($color);
154
                        $plot->SetFillColor($color);
155
                        $plot->SetShadow('red', 3, 4, false);
156
                    }
157
                    break;
158
                }
159
160
            case 'LinePlot':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
161
                {
162
                    $plot->Clear();
163
                    $plot->SetColor($this->GetNextColor() . '@0.4');
164
                    $plot->SetWeight(2);
165
                    break;
166
                }
167
168
            case 'PiePlot':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
169
                {
170
                    $plot->SetCenter(0.5, 0.45);
171
                    $plot->ShowBorder(false);
172
                    $plot->SetSliceColors($this->GetThemeColors());
173
                    break;
174
                }
175
176
            case 'PiePlot3D':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
177
                {
178
                    $plot->SetSliceColors($this->GetThemeColors());
179
                    break;
180
                }
181
182
            default:
0 ignored issues
show
Coding Style introduced by
DEFAULT statements must be defined using a colon

As per the PSR-2 coding standard, default statements should not be wrapped in curly braces.

switch ($expr) {
    default: { //wrong
        doSomething();
        break;
    }
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
183
                {
184
                }
185
        }
186
    }
187
}
188