Passed
Push — master ( 8f5e6a...061d3e )
by Felipe
03:26
created

PolarAxis::ShowAngleLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Amenadiel\JpGraph\Graph;
3
4
use Amenadiel\JpGraph\Util;
5
6
//--------------------------------------------------------------------------
7
// class PolarAxis
8
//--------------------------------------------------------------------------
9
class PolarAxis extends Axis
10
{
11
    private $angle_step        = 15;
12
    private $angle_color        = 'lightgray';
13
    private $angle_label_color        = 'black';
0 ignored issues
show
Unused Code introduced by
The property $angle_label_color is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
    private $angle_fontfam     = FF_FONT1;
15
    private $angle_fontstyle     = FS_NORMAL;
16
    private $angle_fontsize     = 10;
17
    private $angle_fontcolor   = 'navy';
18
    private $gridminor_color   = 'lightgray';
19
    private $gridmajor_color   = 'lightgray';
20
    private $show_minor_grid   = false;
21
    private $show_major_grid   = true;
22
    private $show_angle_mark   = true;
23
    private $show_angle_grid   = true;
24
    private $show_angle_label   = true;
25
    private $angle_tick_len    = 3;
26
    private $angle_tick_len2    = 3;
27
    private $angle_tick_color    = 'black';
28
    private $show_angle_tick   = true;
29
    private $radius_tick_color = 'black';
30
31
    public function __construct($img, $aScale)
32
    {
33
        parent::__construct($img, $aScale);
34
    }
35
36
    public function ShowAngleDegreeMark($aFlg = true)
37
    {
38
        $this->show_angle_mark = $aFlg;
39
    }
40
41
    public function SetAngleStep($aStep)
42
    {
43
        $this->angle_step = $aStep;
44
    }
45
46
    public function HideTicks($aFlg = true, $aAngleFlg = true)
47
    {
48
        parent::HideTicks($aFlg, $aFlg);
49
        $this->show_angle_tick = !$aAngleFlg;
50
    }
51
52
    public function ShowAngleLabel($aFlg = true)
53
    {
54
        $this->show_angle_label = $aFlg;
55
    }
56
57
    public function ShowGrid($aMajor = true, $aMinor = false, $aAngle = true)
58
    {
59
        $this->show_minor_grid = $aMinor;
60
        $this->show_major_grid = $aMajor;
61
        $this->show_angle_grid = $aAngle;
62
    }
63
64
    public function SetAngleFont($aFontFam, $aFontStyle = FS_NORMAL, $aFontSize = 10)
65
    {
66
        $this->angle_fontfam   = $aFontFam;
67
        $this->angle_fontstyle = $aFontStyle;
68
        $this->angle_fontsize  = $aFontSize;
69
    }
70
71
    public function SetColor($aColor, $aRadColor = '', $aAngleColor = '')
72
    {
73
        if ($aAngleColor == '') {
74
            $aAngleColor = $aColor;
75
        }
76
77
        parent::SetColor($aColor, $aRadColor);
0 ignored issues
show
Documentation introduced by
$aRadColor is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
        $this->angle_fontcolor = $aAngleColor;
79
    }
80
81
    public function SetGridColor($aMajorColor, $aMinorColor = '', $aAngleColor = '')
82
    {
83
        if ($aMinorColor == '') {
84
            $aMinorColor = $aMajorColor;
85
        }
86
87
        if ($aAngleColor == '') {
88
            $aAngleColor = $aMajorColor;
89
        }
90
91
        $this->gridminor_color = $aMinorColor;
92
        $this->gridmajor_color = $aMajorColor;
93
        $this->angle_color     = $aAngleColor;
94
    }
95
96
    public function SetTickColors($aRadColor, $aAngleColor = '')
97
    {
98
        $this->radius_tick_color = $aRadColor;
99
        $this->angle_tick_color  = $aAngleColor;
100
    }
101
102
    // Private methods
103
    public function StrokeGrid($pos)
104
    {
105
        $x = round($this->img->left_margin + $this->img->plotwidth / 2);
106
        $this->scale->ticks->Stroke($this->img, $this->scale, $pos);
107
108
        // Stroke the minor arcs
109
        $pmin = [];
110
        $p    = $this->scale->ticks->ticks_pos;
111
        $n    = count($p);
112
        $i    = 0;
113
        $this->img->SetColor($this->gridminor_color);
114
        while ($i < $n) {
115
            $r      = $p[$i] - $x + 1;
116
            $pmin[] = $r;
117
            if ($this->show_minor_grid) {
118
                $this->img->Circle($x, $pos, $r);
119
            }
120
            $i++;
121
        }
122
123
        $limit = max($this->img->plotwidth, $this->img->plotheight) * 1.4;
124
        while ($r < $limit) {
0 ignored issues
show
Bug introduced by
The variable $r does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
125
            $off = $r;
126
            $i   = 1;
127
            $r   = $off + round($p[$i] - $x + 1);
128
            while ($r < $limit && $i < $n) {
129
                $r      = $off + $p[$i] - $x;
130
                $pmin[] = $r;
131
                if ($this->show_minor_grid) {
132
                    $this->img->Circle($x, $pos, $r);
133
                }
134
                $i++;
135
            }
136
        }
137
138
        // Stroke the major arcs
139
        if ($this->show_major_grid) {
140
            // First determine how many minor step on
141
            // every major step. We have recorded the minor radius
142
            // in pmin and use these values. This is done in order
143
            // to avoid rounding errors if we were to recalculate the
144
            // different major radius.
145
            $pmaj = $this->scale->ticks->maj_ticks_pos;
146
            $p    = $this->scale->ticks->ticks_pos;
147
            if ($this->scale->name == 'lin') {
148
                $step = round(($pmaj[1] - $pmaj[0]) / ($p[1] - $p[0]));
149
            } else {
150
                $step = 9;
151
            }
152
            $n = round(count($pmin) / $step);
153
            $i = 0;
0 ignored issues
show
Unused Code introduced by
$i is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
154
            $this->img->SetColor($this->gridmajor_color);
155
            $limit = max($this->img->plotwidth, $this->img->plotheight) * 1.4;
156
            $off   = $r;
0 ignored issues
show
Unused Code introduced by
$off is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
157
            $i     = 0;
158
            $r     = $pmin[$i * $step];
159
            while ($r < $limit && $i < $n) {
160
                $r = $pmin[$i * $step];
161
                $this->img->Circle($x, $pos, $r);
162
                $i++;
163
            }
164
        }
165
166
        // Draw angles
167
        if ($this->show_angle_grid) {
168
            $this->img->SetColor($this->angle_color);
169
            $d            = max($this->img->plotheight, $this->img->plotwidth) * 1.4;
170
            $a            = 0;
171
            $p            = $this->scale->ticks->ticks_pos;
172
            $start_radius = $p[1] - $x;
173
            while ($a < 360) {
174
                if ($a == 90 || $a == 270) {
175
                    // Make sure there are no rounding problem with
176
                    // exactly vertical lines
177
                    $this->img->Line($x + $start_radius * cos($a / 180 * M_PI) + 1,
178
                        $pos - $start_radius * sin($a / 180 * M_PI),
179
                        $x + $start_radius * cos($a / 180 * M_PI) + 1,
180
                        $pos - $d * sin($a / 180 * M_PI));
181
                } else {
182
                    $this->img->Line($x + $start_radius * cos($a / 180 * M_PI) + 1,
183
                        $pos - $start_radius * sin($a / 180 * M_PI),
184
                        $x + $d * cos($a / 180 * M_PI),
185
                        $pos - $d * sin($a / 180 * M_PI));
186
                }
187
                $a += $this->angle_step;
188
            }
189
        }
190
    }
191
192
    public function StrokeAngleLabels($pos, $type)
193
    {
194
        if (!$this->show_angle_label) {
195
            return;
196
        }
197
198
        $x0 = round($this->img->left_margin + $this->img->plotwidth / 2) + 1;
199
200
        $d = max($this->img->plotwidth, $this->img->plotheight) * 1.42;
201
        $a = $this->angle_step;
202
        $t = new Text();
203
        $t->SetColor($this->angle_fontcolor);
204
        $t->SetFont($this->angle_fontfam, $this->angle_fontstyle, $this->angle_fontsize);
205
        $xright  = $this->img->width - $this->img->right_margin;
206
        $ytop    = $this->img->top_margin;
207
        $xleft   = $this->img->left_margin;
208
        $ybottom = $this->img->height - $this->img->bottom_margin;
209
        $ha      = 'left';
210
        $va      = 'center';
211
        $w       = $this->img->plotwidth / 2;
212
        $h       = $this->img->plotheight / 2;
213
        $xt      = $x0;
214
        $yt      = $pos;
215
        $margin  = 5;
216
217
        $tl  = $this->angle_tick_len; // Outer len
218
        $tl2 = $this->angle_tick_len2; // Interior len
219
220
        $this->img->SetColor($this->angle_tick_color);
221
        $rot90 = $this->img->a == 90;
222
223
        if ($type == POLAR_360) {
224
225
            // Corner angles of the four corners
226
            $ca1 = atan($h / $w) / M_PI * 180;
227
            $ca2 = 180 - $ca1;
228
            $ca3 = $ca1 + 180;
229
            $ca4 = 360 - $ca1;
230
            $end = 360;
231
232
            while ($a < $end) {
233
                $ca = cos($a / 180 * M_PI);
234
                $sa = sin($a / 180 * M_PI);
235
                $x  = $d * $ca;
236
                $y  = $d * $sa;
237
                $xt = 1000;
0 ignored issues
show
Unused Code introduced by
$xt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
238
                $yt = 1000;
0 ignored issues
show
Unused Code introduced by
$yt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
239
                if ($a <= $ca1 || $a >= $ca4) {
240
                    $yt = $pos - $w * $y / $x;
241
                    $xt = $xright + $margin;
242
                    if ($rot90) {
243
                        $ha = 'center';
244
                        $va = 'top';
245
                    } else {
246
                        $ha = 'left';
247
                        $va = 'center';
248
                    }
249
                    $x1 = $xright - $tl2;
250
                    $x2 = $xright + $tl;
251
                    $y1 = $y2 = $yt;
252 View Code Duplication
                } elseif ($a > $ca1 && $a < $ca2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
253
                    $xt = $x0 + $h * $x / $y;
254
                    $yt = $ytop - $margin;
255
                    if ($rot90) {
256
                        $ha = 'left';
257
                        $va = 'center';
258
                    } else {
259
                        $ha = 'center';
260
                        $va = 'bottom';
261
                    }
262
                    $y1 = $ytop + $tl2;
263
                    $y2 = $ytop - $tl;
264
                    $x1 = $x2 = $xt;
265
                } elseif ($a >= $ca2 && $a <= $ca3) {
266
                    $yt = $pos + $w * $y / $x;
267
                    $xt = $xleft - $margin;
268
                    if ($rot90) {
269
                        $ha = 'center';
270
                        $va = 'bottom';
271
                    } else {
272
                        $ha = 'right';
273
                        $va = 'center';
274
                    }
275
                    $x1 = $xleft + $tl2;
276
                    $x2 = $xleft - $tl;
277
                    $y1 = $y2 = $yt;
278
                } else {
279
                    $xt = $x0 - $h * $x / $y;
280
                    $yt = $ybottom + $margin;
281
                    if ($rot90) {
282
                        $ha = 'right';
283
                        $va = 'center';
284
                    } else {
285
                        $ha = 'center';
286
                        $va = 'top';
287
                    }
288
                    $y1 = $ybottom - $tl2;
289
                    $y2 = $ybottom + $tl;
290
                    $x1 = $x2 = $xt;
291
                }
292
                if ($a != 0 && $a != 180) {
293
                    $t->Align($ha, $va);
294
                    if ($this->scale->clockwise) {
295
                        $t->Set(360 - $a);
296
                    } else {
297
                        $t->Set($a);
298
                    }
299
                    if ($this->show_angle_mark && $t->font_family > 4) {
300
                        $a .= SymChar::Get('degree');
301
                    }
302
                    $t->Stroke($this->img, $xt, $yt);
303
                    if ($this->show_angle_tick) {
304
                        $this->img->Line($x1, $y1, $x2, $y2);
305
                    }
306
                }
307
                $a += $this->angle_step;
308
            }
309
        } else {
310
            // POLAR_HALF
311
            $ca1 = atan($h / $w * 2) / M_PI * 180;
312
            $ca2 = 180 - $ca1;
313
            $end = 180;
314
            while ($a < $end) {
315
                $ca = cos($a / 180 * M_PI);
316
                $sa = sin($a / 180 * M_PI);
317
                $x  = $d * $ca;
318
                $y  = $d * $sa;
319
                if ($a <= $ca1) {
320
                    $yt = $pos - $w * $y / $x;
321
                    $xt = $xright + $margin;
322
                    if ($rot90) {
323
                        $ha = 'center';
324
                        $va = 'top';
325
                    } else {
326
                        $ha = 'left';
327
                        $va = 'center';
328
                    }
329
                    $x1 = $xright - $tl2;
330
                    $x2 = $xright + $tl;
331
                    $y1 = $y2 = $yt;
332 View Code Duplication
                } elseif ($a > $ca1 && $a < $ca2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
333
                    $xt = $x0 + 2 * $h * $x / $y;
334
                    $yt = $ytop - $margin;
335
                    if ($rot90) {
336
                        $ha = 'left';
337
                        $va = 'center';
338
                    } else {
339
                        $ha = 'center';
340
                        $va = 'bottom';
341
                    }
342
                    $y1 = $ytop + $tl2;
343
                    $y2 = $ytop - $tl;
344
                    $x1 = $x2 = $xt;
345
                } elseif ($a >= $ca2) {
346
                    $yt = $pos + $w * $y / $x;
347
                    $xt = $xleft - $margin;
348
                    if ($rot90) {
349
                        $ha = 'center';
350
                        $va = 'bottom';
351
                    } else {
352
                        $ha = 'right';
353
                        $va = 'center';
354
                    }
355
                    $x1 = $xleft + $tl2;
356
                    $x2 = $xleft - $tl;
357
                    $y1 = $y2 = $yt;
358
                }
359
                $t->Align($ha, $va);
360
                if ($this->show_angle_mark && $t->font_family > 4) {
361
                    $a .= SymChar::Get('degree');
362
                }
363
                $t->Set($a);
364
                $t->Stroke($this->img, $xt, $yt);
365
                if ($this->show_angle_tick) {
366
                    $this->img->Line($x1, $y1, $x2, $y2);
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $x2 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y2 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
367
                }
368
                $a += $this->angle_step;
369
            }
370
        }
371
    }
372
373
    public function Stroke($pos, $dummy = true)
374
    {
375
        $this->img->SetLineWeight($this->weight);
376
        $this->img->SetColor($this->color);
377
        $this->img->SetFont($this->font_family, $this->font_style, $this->font_size);
378 View Code Duplication
        if (!$this->hide_line) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
379
            $this->img->FilledRectangle($this->img->left_margin, $pos,
380
                $this->img->width - $this->img->right_margin,
381
                $pos + $this->weight - 1);
382
        }
383
        $y = $pos + $this->img->GetFontHeight() + $this->title_margin + $this->title->margin;
0 ignored issues
show
Bug introduced by
The property margin does not seem to exist. Did you mean _margin?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
384
        if ($this->title_adjust == "high") {
385
            $this->title->SetPos($this->img->width - $this->img->right_margin, $y, "right", "top");
386
        } elseif ($this->title_adjust == "middle" || $this->title_adjust == "center") {
387
            $this->title->SetPos(($this->img->width - $this->img->left_margin - $this->img->right_margin) / 2 + $this->img->left_margin,
388
                $y, "center", "top");
389
        } elseif ($this->title_adjust == "low") {
390
            $this->title->SetPos($this->img->left_margin, $y, "left", "top");
391
        } else {
392
            Util\JpGraphError::RaiseL(17002, $this->title_adjust);
393
            //('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')');
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...
394
        }
395
396
        if (!$this->hide_labels) {
397
            $this->StrokeLabels($pos, false);
398
        }
399
        $this->img->SetColor($this->radius_tick_color);
400
        $this->scale->ticks->Stroke($this->img, $this->scale, $pos);
401
402
        //
403
        // Mirror the positions for the left side of the scale
404
        //
405
        $mid = 2 * ($this->img->left_margin + $this->img->plotwidth / 2);
406
        $n   = count($this->scale->ticks->ticks_pos);
407
        $i   = 0;
408 View Code Duplication
        while ($i < $n) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
409
            $this->scale->ticks->ticks_pos[$i] =
410
            $mid - $this->scale->ticks->ticks_pos[$i];
411
            ++$i;
412
        }
413
414
        $n = count($this->scale->ticks->maj_ticks_pos);
415
        $i = 0;
416 View Code Duplication
        while ($i < $n) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
417
            $this->scale->ticks->maj_ticks_pos[$i] =
418
            $mid - $this->scale->ticks->maj_ticks_pos[$i];
419
            ++$i;
420
        }
421
422
        $n = count($this->scale->ticks->maj_ticklabels_pos);
423
        $i = 1;
424 View Code Duplication
        while ($i < $n) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
425
            $this->scale->ticks->maj_ticklabels_pos[$i] =
426
            $mid - $this->scale->ticks->maj_ticklabels_pos[$i];
427
            ++$i;
428
        }
429
430
        // Draw the left side of the scale
431
        $n  = count($this->scale->ticks->ticks_pos);
432
        $yu = $pos - $this->scale->ticks->direction * $this->scale->ticks->GetMinTickAbsSize();
433
434
        // Minor ticks
435 View Code Duplication
        if (!$this->scale->ticks->supress_minor_tickmarks) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
436
            $i = 1;
437
            while ($i < $n / 2) {
438
                $x = round($this->scale->ticks->ticks_pos[$i]);
439
                $this->img->Line($x, $pos, $x, $yu);
440
                ++$i;
441
            }
442
        }
443
444
        $n  = count($this->scale->ticks->maj_ticks_pos);
445
        $yu = $pos - $this->scale->ticks->direction * $this->scale->ticks->GetMajTickAbsSize();
446
447
        // Major ticks
448 View Code Duplication
        if (!$this->scale->ticks->supress_tickmarks) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
449
            $i = 1;
450
            while ($i < $n / 2) {
451
                $x = round($this->scale->ticks->maj_ticks_pos[$i]);
452
                $this->img->Line($x, $pos, $x, $yu);
453
                ++$i;
454
            }
455
        }
456
        if (!$this->hide_labels) {
457
            $this->StrokeLabels($pos, false);
458
        }
459
        $this->title->Stroke($this->img);
460
    }
461
}
462