Completed
Push — master ( 061d3e...3e5ec1 )
by Felipe
13s
created

Image::RoundedRectangle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 5
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace Amenadiel\JpGraph\Image;
4
5
use \Amenadiel\JpGraph\Text\LanguageConv;
6
use \Amenadiel\JpGraph\Text\TTF;
7
use \Amenadiel\JpGraph\Util;
8
use \Amenadiel\JpGraph\Util\ErrMsgText;
9
10
//=======================================================================
11
// File:        GD_IMAGE.INC.PHP
12
// Description: PHP Graph Plotting library. Low level image drawing routines
13
// Created:     2001-01-08, refactored 2008-03-29
14
// Ver:         $Id: gd_image.inc.php 1922 2010-01-11 11:42:50Z ljp $
15
//
16
// Copyright (c) Asial Corporation. All rights reserved.
17
//========================================================================
18
19
//========================================================================
20
// CLASS Image
21
// Description: The very coor image drawing class that encapsulates all
22
//              calls to the GD library
23
//              Note: The class used by the library is the decendant
24
//              class RotImage which extends the Image class with transparent
25
//              rotation.
26
//=========================================================================
27
class Image
28
{
29
    public $img = null;
30
    public $rgb = null;
31
    public $img_format;
32
    public $ttf        = null;
33
    public $line_style = LINESTYLE_SOLID;
34
    public $current_color;
35
    public $current_color_name;
36
    public $original_width = 0;
37
    public $original_height = 0;
38
    public $plotwidth      = 0;
39
    public $plotheight      = 0;
40
41
    // for __get, __set
42
    private $_left_margin = 30;
0 ignored issues
show
Unused Code introduced by
The property $_left_margin 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...
43
    private $_right_margin = 30;
0 ignored issues
show
Unused Code introduced by
The property $_right_margin 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...
44
    private $_top_margin = 20;
0 ignored issues
show
Unused Code introduced by
The property $_top_margin 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...
45
    private $_bottom_margin = 30;
0 ignored issues
show
Unused Code introduced by
The property $_bottom_margin 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...
46
    //private $_plotwidth=0,$_plotheight=0;
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...
47
    private $_width       = 0;
0 ignored issues
show
Unused Code introduced by
The property $_width 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...
48
    private $_height       = 0;
0 ignored issues
show
Unused Code introduced by
The property $_height 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...
49
    private $_line_weight = 1;
0 ignored issues
show
Unused Code introduced by
The property $_line_weight 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...
50
51
    protected $expired           = true;
52
    protected $lastx             = 0;
53
    protected $lasty             = 0;
54
    protected $obs_list          = [];
55
    protected $font_size         = 12;
56
    protected $font_family         = FF_DEFAULT;
57
    protected $font_style         = FS_NORMAL;
58
    protected $font_file         = '';
59
    protected $text_halign       = "left";
60
    protected $text_valign       = "bottom";
61
    protected $use_anti_aliasing = false;
62
    protected $quality           = null;
63
    protected $colorstack        = [];
64
    protected $colorstackidx        = 0;
65
    protected $canvascolor       = 'white';
66
    protected $langconv          = null;
67
    protected $iInterlace        = false;
68
    protected $bbox_cache        = []; // STore the last found tetx bounding box
69
    protected $ff_font0;
70
    protected $ff_font0_bold;
71
    protected $ff_font1;
72
    protected $ff_font1_bold;
73
    protected $ff_font2;
74
    protected $ff_font2_bold;
75
76
    //---------------
77
    // CONSTRUCTOR
78
    public function __construct($aWidth = 0, $aHeight = 0, $aFormat = DEFAULT_GFORMAT, $aSetAutoMargin = true)
79
    {
80
        $this->original_width  = $aWidth;
81
        $this->original_height = $aHeight;
82
        $this->CreateImgCanvas($aWidth, $aHeight);
83
84
        if ($aSetAutoMargin) {
85
            $this->SetAutoMargin();
86
        }
87
88
        if (!$this->SetImgFormat($aFormat)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->SetImgFormat($aFormat) of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
89
            Util\JpGraphError::RaiseL(25081, $aFormat); //("JpGraph: Selected graphic format is either not supported or unknown [$aFormat]");
90
        }
91
        $this->ttf      = new TTF();
92
        $this->langconv = new LanguageConv();
93
94
        $this->ff_font0      = imageloadfont(dirname(dirname(__FILE__)) . "/fonts/FF_FONT0.gdf");
95
        $this->ff_font1      = imageloadfont(dirname(dirname(__FILE__)) . "/fonts/FF_FONT1.gdf");
96
        $this->ff_font2      = imageloadfont(dirname(dirname(__FILE__)) . "/fonts/FF_FONT2.gdf");
97
        $this->ff_font1_bold = imageloadfont(dirname(dirname(__FILE__)) . "/fonts/FF_FONT1-Bold.gdf");
98
        $this->ff_font2_bold = imageloadfont(dirname(dirname(__FILE__)) . "/fonts/FF_FONT2-Bold.gdf");
99
    }
100
101
    // Enable interlacing in images
102
    public function SetInterlace($aFlg = true)
103
    {
104
        $this->iInterlace = $aFlg;
105
    }
106
107
    // Should we use anti-aliasing. Note: This really slows down graphics!
108
    public function SetAntiAliasing($aFlg = true)
109
    {
110
        $this->use_anti_aliasing = $aFlg;
111
        if (function_exists('imageantialias')) {
112
            imageantialias($this->img, $aFlg);
113
        } /*else {
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...
114
    Util\JpGraphError::RaiseL(25128); //('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.')
115
    }*/
116
    }
117
118
    public function GetAntiAliasing()
119
    {
120
        return $this->use_anti_aliasing;
121
    }
122
123
    public function CreateRawCanvas($aWidth = 0, $aHeight = 0)
124
    {
125
        $aWidth *= SUPERSAMPLING_SCALE;
126
        $aHeight *= SUPERSAMPLING_SCALE;
127
128
        if ($aWidth <= 1 || $aHeight <= 1) {
129
            Util\JpGraphError::RaiseL(25082, $aWidth, $aHeight); //("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)");
130
        }
131
132
        $this->img = @imagecreatetruecolor($aWidth, $aHeight);
133
        if ($this->img < 1) {
134
            Util\JpGraphError::RaiseL(25126);
135
            //die("Can't create truecolor image. Check that you really have GD2 library installed.");
136
        }
137
        $this->SetAlphaBlending();
138
139
        if ($this->iInterlace) {
140
            imageinterlace($this->img, 1);
141
        }
142
        if ($this->rgb != null) {
143
            $this->rgb->img = $this->img;
144
        } else {
145
            $this->rgb = new RGB($this->img);
146
        }
147
    }
148
149
    public function CloneCanvasH()
150
    {
151
        $oldimage = $this->img;
152
        $this->CreateRawCanvas($this->width, $this->height);
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
153
        imagecopy($this->img, $oldimage, 0, 0, 0, 0, $this->width, $this->height);
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
154
        return $oldimage;
155
    }
156
157
    public function CreateImgCanvas($aWidth = 0, $aHeight = 0)
158
    {
159
        $old = [$this->img, $this->width, $this->height];
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
160
161
        $aWidth  = round($aWidth);
162
        $aHeight = round($aHeight);
163
164
        $this->width  = $aWidth;
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
165
        $this->height = $aHeight;
0 ignored issues
show
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
166
167
        if ($aWidth == 0 || $aHeight == 0) {
168
            // We will set the final size later.
169
            // Note: The size must be specified before any other
170
            // img routines that stroke anything are called.
171
            $this->img = null;
172
            $this->rgb = null;
173
            return $old;
174
        }
175
176
        $this->CreateRawCanvas($aWidth, $aHeight);
177
        // Set canvas color (will also be the background color for a
178
        // a pallett image
179
        $this->SetColor($this->canvascolor);
180
        $this->FilledRectangle(0, 0, $this->width - 1, $this->height - 1);
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
181
182
        return $old;
183
    }
184
185
    public function CopyCanvasH($aToHdl, $aFromHdl, $aToX, $aToY, $aFromX, $aFromY, $aWidth, $aHeight, $aw = -1, $ah = -1)
186
    {
187
        if ($aw === -1) {
188
            $aw = $aWidth;
189
            $ah = $aHeight;
190
            $f  = 'imagecopyresized';
191
        } else {
192
            $f = 'imagecopyresampled';
193
        }
194
        $f($aToHdl, $aFromHdl, $aToX, $aToY, $aFromX, $aFromY, $aWidth, $aHeight, $aw, $ah);
195
    }
196
197
    public function Copy($fromImg, $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $fromWidth = -1, $fromHeight = -1)
198
    {
199
        $this->CopyCanvasH($this->img, $fromImg, $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $fromWidth, $fromHeight);
200
    }
201
202
    public function CopyMerge($fromImg, $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $fromWidth = -1, $fromHeight = -1, $aMix = 100)
203
    {
204
        if ($aMix == 100) {
205
            $this->CopyCanvasH($this->img, $fromImg,
206
                $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $fromWidth, $fromHeight);
207
        } else {
208
            if (($fromWidth != -1 && ($fromWidth != $toWidth)) || ($fromHeight != -1 && ($fromHeight != $fromHeight))) {
209
                // Create a new canvas that will hold the re-scaled original from image
210
                if ($toWidth <= 1 || $toHeight <= 1) {
211
                    Util\JpGraphError::RaiseL(25083); //('Illegal image size when copying image. Size for copied to image is 1 pixel or less.');
212
                }
213
214
                $tmpimg = @imagecreatetruecolor($toWidth, $toHeight);
215
216
                if ($tmpimg < 1) {
217
                    Util\JpGraphError::RaiseL(25084); //('Failed to create temporary GD canvas. Out of memory ?');
218
                }
219
                $this->CopyCanvasH($tmpimg, $fromImg, 0, 0, 0, 0,
220
                    $toWidth, $toHeight, $fromWidth, $fromHeight);
221
                $fromImg = $tmpimg;
222
            }
223
            imagecopymerge($this->img, $fromImg, $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $aMix);
224
        }
225
    }
226
227
    public static function GetWidth($aImg = null)
228
    {
229
        if ($aImg === null) {
230
            $aImg = $this->img;
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
231
        }
232
        return imagesx($aImg);
233
    }
234
235
    public static function GetHeight($aImg = null)
236
    {
237
        if ($aImg === null) {
238
            $aImg = $this->img;
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
239
        }
240
        return imagesy($aImg);
241
    }
242
243
    public static function CreateFromString($aStr)
244
    {
245
        $img = imagecreatefromstring($aStr);
246
        if ($img === false) {
247
            Util\JpGraphError::RaiseL(25085);
248
            //('An image can not be created from the supplied string. It is either in a format not supported or the string is representing an corrupt image.');
249
        }
250
        return $img;
251
    }
252
253
    public function SetCanvasH($aHdl)
254
    {
255
        $this->img      = $aHdl;
256
        $this->rgb->img = $aHdl;
257
    }
258
259
    public function SetCanvasColor($aColor)
260
    {
261
        $this->canvascolor = $aColor;
262
    }
263
264
    public function SetAlphaBlending($aFlg = true)
265
    {
266
        ImageAlphaBlending($this->img, $aFlg);
267
    }
268
269
    public function SetAutoMargin()
270
    {
271
        $min_bm = 5;
272
        $lm     = min(40, $this->width / 7);
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
273
        $rm     = min(20, $this->width / 10);
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
274
        $tm     = max(5, $this->height / 7);
0 ignored issues
show
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
275
        $bm     = max($min_bm, $this->height / 6);
0 ignored issues
show
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
276
        $this->SetMargin($lm, $rm, $tm, $bm);
277
    }
278
279
    //---------------
280
    // PUBLIC METHODS
281
282
    public function SetFont($family, $style = FS_NORMAL, $size = 10)
283
    {
284
        $this->font_family = $family;
285
        $this->font_style  = $style;
286
        $this->font_size   = $size * SUPERSAMPLING_SCALE;
287
        $this->font_file   = '';
288
        if (($this->font_family == FF_FONT1 || $this->font_family == FF_FONT2) && $this->font_style == FS_BOLD) {
289
            ++$this->font_family;
290
        }
291
        if ($this->font_family > FF_FONT2 + 1) {
292
            // A TTF font so get the font file
293
294
            // Check that this PHP has support for TTF fonts
295
            if (!function_exists('imagettfbbox')) {
296
                // use internal font when php is configured without '--with-ttf'
297
                $this->font_family = FF_FONT1;
298
                //  Util\JpGraphError::RaiseL(25087);//('This PHP build has not been configured with TTF support. You need to recompile your PHP installation with FreeType support.');
1 ignored issue
show
Unused Code Comprehensibility introduced by
63% 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...
299
            } else {
300
                $this->font_file = $this->ttf->File($this->font_family, $this->font_style);
301
            }
302
        }
303
    }
304
305
    // Get the specific height for a text string
306
    public function GetTextHeight($txt = "", $angle = 0)
307
    {
308
        $tmp = preg_split('/\n/', $txt);
309
        $n   = count($tmp);
310
        $m   = 0;
311
        for ($i = 0; $i < $n; ++$i) {
312
            $m = max($m, strlen($tmp[$i]));
313
        }
314
315
        if ($this->font_family <= FF_FONT2 + 1) {
316 View Code Duplication
            if ($angle == 0) {
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...
317
                $h = imagefontheight($this->font_family);
318
                if ($h === false) {
319
                    Util\JpGraphError::RaiseL(25088); //('You have a misconfigured GD font support. The call to imagefontwidth() fails.');
320
                }
321
322
                return $n * $h;
323
            } else {
324
                $w = @imagefontwidth($this->font_family);
325
                if ($w === false) {
326
                    Util\JpGraphError::RaiseL(25088); //('You have a misconfigured GD font support. The call to imagefontwidth() fails.');
327
                }
328
329
                return $m * $w;
330
            }
331
        } else {
332
            $bbox = $this->GetTTFBBox($txt, $angle);
333
            return $bbox[1] - $bbox[5] + 1;
334
        }
335
    }
336
337
    // Estimate font height
338
    public function GetFontHeight($angle = 0)
339
    {
340
        $txt = "XOMg";
341
        return $this->GetTextHeight($txt, $angle);
342
    }
343
344
    // Approximate font width with width of letter "O"
345
    public function GetFontWidth($angle = 0)
346
    {
347
        $txt = 'O';
348
        return $this->GetTextWidth($txt, $angle);
349
    }
350
351
    // Get actual width of text in absolute pixels. Note that the width is the
352
    // texts projected with onto the x-axis. Call with angle=0 to get the true
353
    // etxt width.
354
    public function GetTextWidth($txt, $angle = 0)
355
    {
356
        $tmp = preg_split('/\n/', $txt);
357
        $n   = count($tmp);
358
        if ($this->font_family <= FF_FONT2 + 1) {
359
            $m = 0;
360
            for ($i = 0; $i < $n; ++$i) {
361
                $l = strlen($tmp[$i]);
362
                if ($l > $m) {
363
                    $m = $l;
364
                }
365
            }
366
367 View Code Duplication
            if ($angle == 0) {
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...
368
                $w = @imagefontwidth($this->font_family);
369
                if ($w === false) {
370
                    Util\JpGraphError::RaiseL(25088); //('You have a misconfigured GD font support. The call to imagefontwidth() fails.');
371
                }
372
                return $m * $w;
373
            } else {
374
                // 90 degrees internal so height becomes width
375
                $h = @imagefontheight($this->font_family);
376
                if ($h === false) {
377
                    Util\JpGraphError::RaiseL(25089); //('You have a misconfigured GD font support. The call to imagefontheight() fails.');
378
                }
379
                return $n * $h;
380
            }
381
        } else {
382
            // For TTF fonts we must walk through a lines and find the
383
            // widest one which we use as the width of the multi-line
384
            // paragraph
385
            $m = 0;
386
            for ($i = 0; $i < $n; ++$i) {
387
                $bbox = $this->GetTTFBBox($tmp[$i], $angle);
388
                $mm   = $bbox[2] - $bbox[0];
389
                if ($mm > $m) {
390
                    $m = $mm;
391
                }
392
            }
393
            return $m;
394
        }
395
    }
396
397
    // Draw text with a box around it
398
    public function StrokeBoxedText($x, $y, $txt, $dir = 0, $fcolor = "white", $bcolor = "black",
399
        $shadowcolor = false, $paragraph_align = "left",
400
        $xmarg = 6, $ymarg = 4, $cornerradius = 0, $dropwidth = 3)
401
    {
402
        $oldx = $this->lastx;
403
        $oldy = $this->lasty;
404
405 View Code Duplication
        if (!is_numeric($dir)) {
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...
406
            if ($dir == "h") {
407
                $dir = 0;
408
            } elseif ($dir == "v") {
409
                $dir = 90;
410
            } else {
411
                Util\JpGraphError::RaiseL(25090, $dir);
412
            }
413
            //(" Unknown direction specified in call to StrokeBoxedText() [$dir]");
414
        }
415
416
        if ($this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2 + 1) {
417
            $width  = $this->GetTextWidth($txt, $dir);
418
            $height = $this->GetTextHeight($txt, $dir);
419
        } else {
420
            $width  = $this->GetBBoxWidth($txt, $dir);
421
            $height = $this->GetBBoxHeight($txt, $dir);
422
        }
423
424
        $height += 2 * $ymarg;
425
        $width += 2 * $xmarg;
426
427
        if ($this->text_halign == "right") {
428
            $x -= $width;
429
        } elseif ($this->text_halign == "center") {
430
            $x -= $width / 2;
431
        }
432
433
        if ($this->text_valign == "bottom") {
434
            $y -= $height;
435
        } elseif ($this->text_valign == "center") {
436
            $y -= $height / 2;
437
        }
438
439
        $olda = $this->SetAngle(0);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetAngle() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
440
441
        if ($shadowcolor) {
442
            $this->PushColor($shadowcolor);
443
            $this->FilledRoundedRectangle($x - $xmarg + $dropwidth, $y - $ymarg + $dropwidth,
444
                $x + $width + $dropwidth, $y + $height - $ymarg + $dropwidth,
445
                $cornerradius);
446
            $this->PopColor();
447
            $this->PushColor($fcolor);
448
            $this->FilledRoundedRectangle($x - $xmarg, $y - $ymarg,
449
                $x + $width, $y + $height - $ymarg,
450
                $cornerradius);
451
            $this->PopColor();
452
            $this->PushColor($bcolor);
453
            $this->RoundedRectangle($x - $xmarg, $y - $ymarg,
454
                $x + $width, $y + $height - $ymarg, $cornerradius);
455
            $this->PopColor();
456
        } else {
457 View Code Duplication
            if ($fcolor) {
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...
458
                $oc = $this->current_color;
459
                $this->SetColor($fcolor);
460
                $this->FilledRoundedRectangle($x - $xmarg, $y - $ymarg, $x + $width, $y + $height - $ymarg, $cornerradius);
461
                $this->current_color = $oc;
462
            }
463 View Code Duplication
            if ($bcolor) {
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...
464
                $oc = $this->current_color;
465
                $this->SetColor($bcolor);
466
                $this->RoundedRectangle($x - $xmarg, $y - $ymarg, $x + $width, $y + $height - $ymarg, $cornerradius);
467
                $this->current_color = $oc;
468
            }
469
        }
470
471
        $h = $this->text_halign;
472
        $v = $this->text_valign;
473
        $this->SetTextAlign("left", "top");
474
475
        $debug = false;
476
        $this->StrokeText($x, $y, $txt, $dir, $paragraph_align, $debug);
477
478
        $bb = [$x - $xmarg, $y + $height - $ymarg, $x + $width, $y + $height - $ymarg,
479
            $x + $width, $y - $ymarg, $x - $xmarg, $y - $ymarg];
480
        $this->SetTextAlign($h, $v);
481
482
        $this->SetAngle($olda);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetAngle() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
483
        $this->lastx = $oldx;
484
        $this->lasty = $oldy;
485
486
        return $bb;
487
    }
488
489
    // Draw text with a box around it. This time the box will be rotated
490
    // with the text. The previous method will just make a larger enough non-rotated
491
    // box to hold the text inside.
492
    public function StrokeBoxedText2($x, $y, $txt, $dir = 0, $fcolor = "white", $bcolor = "black",
493
        $shadowcolor = false, $paragraph_align = "left",
494
        $xmarg = 6, $ymarg = 4, $cornerradius = 0, $dropwidth = 3)
0 ignored issues
show
Unused Code introduced by
The parameter $cornerradius is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
495
    {
496
497
        // This version of boxed text will stroke a rotated box round the text
498
        // thta will follow the angle of the text.
499
        // This has two implications:
500
        // 1) This methos will only support TTF fonts
501
        // 2) The only two alignment that makes sense are centered or baselined
502
503
        if ($this->font_family <= FF_FONT2 + 1) {
504
            Util\JpGraphError::RaiseL(25131); //StrokeBoxedText2() Only support TTF fonts and not built in bitmap fonts
505
        }
506
507
        $oldx = $this->lastx;
508
        $oldy = $this->lasty;
509
        $dir  = $this->NormAngle($dir);
510
511 View Code Duplication
        if (!is_numeric($dir)) {
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...
512
            if ($dir == "h") {
513
                $dir = 0;
514
            } elseif ($dir == "v") {
515
                $dir = 90;
516
            } else {
517
                Util\JpGraphError::RaiseL(25090, $dir);
518
            }
519
            //(" Unknown direction specified in call to StrokeBoxedText() [$dir]");
520
        }
521
522
        $width       = $this->GetTextWidth($txt, 0) + 2 * $xmarg;
523
        $height      = $this->GetTextHeight($txt, 0) + 2 * $ymarg;
524
        $rect_width  = $this->GetBBoxWidth($txt, $dir);
525
        $rect_height = $this->GetBBoxHeight($txt, $dir);
526
527
        $baseline_offset = $this->bbox_cache[1] - 1;
0 ignored issues
show
Unused Code introduced by
$baseline_offset 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...
528
529
        if ($this->text_halign == "center") {
530
            if ($dir >= 0 && $dir <= 90) {
531
                $x -= $rect_width / 2;
532
                $x += sin($dir * M_PI / 180) * $height;
533
                $y += $rect_height / 2;
534
            } elseif ($dir >= 270 && $dir <= 360) {
535
                $x -= $rect_width / 2;
536
                $y -= $rect_height / 2;
537
                $y += cos($dir * M_PI / 180) * $height;
538
            } elseif ($dir >= 90 && $dir <= 180) {
539
                $x += $rect_width / 2;
540
                $y += $rect_height / 2;
541
                $y += cos($dir * M_PI / 180) * $height;
542
            } else {
543
                // $dir > 180 &&  $dir < 270
1 ignored issue
show
Unused Code Comprehensibility introduced by
36% 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...
544
                $x += $rect_width / 2;
545
                $x += sin($dir * M_PI / 180) * $height;
546
                $y -= $rect_height / 2;
547
            }
548
        }
549
550
        // Rotate the box around this point
551
        $this->SetCenter($x, $y);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetCenter() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
552
        $olda = $this->SetAngle(-$dir);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetAngle() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
553
554
        // We need to use adjusted coordinats for the box to be able
555
        // to draw the box below the baseline. This cannot be done before since
556
        // the rotating point must be the original x,y since that is arounbf the
557
        // point where the text will rotate and we cannot change this since
558
        // that is where the GD/GreeType will rotate the text
559
560
        // For smaller <14pt font we need to do some additional
561
        // adjustments to make it look good
562
        if ($this->font_size < 14) {
563
            $x -= 2;
564
            $y += 2;
565
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
566
            //  $y += $baseline_offset;
1 ignored issue
show
Unused Code Comprehensibility introduced by
38% 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...
567
        }
568
569
        if ($shadowcolor) {
570
            $this->PushColor($shadowcolor);
571
            $this->FilledRectangle($x - $xmarg + $dropwidth, $y + $ymarg + $dropwidth - $height,
572
                $x + $width + $dropwidth, $y + $ymarg + $dropwidth);
573
            //$cornerradius);
574
            $this->PopColor();
575
            $this->PushColor($fcolor);
576
            $this->FilledRectangle($x - $xmarg, $y + $ymarg - $height,
577
                $x + $width, $y + $ymarg);
578
            //$cornerradius);
579
            $this->PopColor();
580
            $this->PushColor($bcolor);
581
            $this->Rectangle($x - $xmarg, $y + $ymarg - $height,
582
                $x + $width, $y + $ymarg);
583
            //$cornerradius);
584
            $this->PopColor();
585
        } else {
586 View Code Duplication
            if ($fcolor) {
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...
587
                $oc = $this->current_color;
588
                $this->SetColor($fcolor);
589
                $this->FilledRectangle($x - $xmarg, $y + $ymarg - $height, $x + $width, $y + $ymarg); //,$cornerradius);
590
                $this->current_color = $oc;
591
            }
592 View Code Duplication
            if ($bcolor) {
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...
593
                $oc = $this->current_color;
594
                $this->SetColor($bcolor);
595
                $this->Rectangle($x - $xmarg, $y + $ymarg - $height, $x + $width, $y + $ymarg); //,$cornerradius);
596
                $this->current_color = $oc;
597
            }
598
        }
599
600
        if ($this->font_size < 14) {
601
            $x += 2;
602
            $y -= 2;
603
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
604
605
            // Restore the original y before we stroke the text
606
            // $y -= $baseline_offset;
1 ignored issue
show
Unused Code Comprehensibility introduced by
43% 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...
607
        }
608
609
        $this->SetCenter(0, 0);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetCenter() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
610
        $this->SetAngle($olda);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetAngle() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
611
612
        $h = $this->text_halign;
613
        $v = $this->text_valign;
614
        if ($this->text_halign == 'center') {
615
            $this->SetTextAlign('center', 'basepoint');
616
        } else {
617
            $this->SetTextAlign('basepoint', 'basepoint');
618
        }
619
620
        $debug = false;
621
        $this->StrokeText($x, $y, $txt, $dir, $paragraph_align, $debug);
622
623
        $bb = [$x - $xmarg, $y + $height - $ymarg,
624
            $x + $width, $y + $height - $ymarg,
625
            $x + $width, $y - $ymarg,
626
            $x - $xmarg, $y - $ymarg];
627
628
        $this->SetTextAlign($h, $v);
629
        $this->SetAngle($olda);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Amenadiel\JpGraph\Image\Image as the method SetAngle() does only exist in the following sub-classes of Amenadiel\JpGraph\Image\Image: Amenadiel\JpGraph\Image\RotImage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
630
631
        $this->lastx = $oldx;
632
        $this->lasty = $oldy;
633
634
        return $bb;
635
    }
636
637
    // Set text alignment
638
    public function SetTextAlign($halign, $valign = "bottom")
639
    {
640
        $this->text_halign = $halign;
641
        $this->text_valign = $valign;
642
    }
643
644
    public function _StrokeBuiltinFont($x, $y, $txt, $dir, $paragraph_align, &$aBoundingBox, $aDebug = false)
645
    {
646
        if (is_numeric($dir) && $dir != 90 && $dir != 0) {
647
            Util\JpGraphError::RaiseL(25091);
648
        }
649
        //(" Internal font does not support drawing text at arbitrary angle. Use TTF fonts instead.");
650
651
        $h  = $this->GetTextHeight($txt);
652
        $fh = $this->GetFontHeight();
653
        $w  = $this->GetTextWidth($txt);
654
655 View Code Duplication
        if ($this->text_halign == "right") {
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...
656
            $x -= $dir == 0 ? $w : $h;
657
        } elseif ($this->text_halign == "center") {
658
            // For center we subtract 1 pixel since this makes the middle
659
            // be prefectly in the middle
660
            $x -= $dir == 0 ? $w / 2 - 1 : $h / 2;
661
        }
662 View Code Duplication
        if ($this->text_valign == "top") {
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...
663
            $y += $dir == 0 ? $h : $w;
664
        } elseif ($this->text_valign == "center") {
665
            $y += $dir == 0 ? $h / 2 : $w / 2;
666
        }
667
668
        $use_font = $this->font_family;
669
670
        if ($dir == 90) {
671
            imagestringup($this->img, $use_font, $x, $y, $txt, $this->current_color);
672
            $aBoundingBox = [round($x), round($y), round($x), round($y - $w), round($x + $h), round($y - $w), round($x + $h), round($y)];
673
            if ($aDebug) {
674
                // Draw bounding box
675
                $this->PushColor('green');
676
                $this->Polygon($aBoundingBox, true);
677
                $this->PopColor();
678
            }
679
        } else {
680
            if (preg_match('/\n/', $txt)) {
681
                $tmp = preg_split('/\n/', $txt);
682
                for ($i = 0; $i < count($tmp); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
683
                    $w1 = $this->GetTextWidth($tmp[$i]);
684
                    if ($paragraph_align == "left") {
685
                        imagestring($this->img, $use_font, $x, $y - $h + 1 + $i * $fh, $tmp[$i], $this->current_color);
686
                    } elseif ($paragraph_align == "right") {
687
                        imagestring($this->img, $use_font, $x + ($w - $w1), $y - $h + 1 + $i * $fh, $tmp[$i], $this->current_color);
688
                    } else {
689
                        imagestring($this->img, $use_font, $x + $w / 2 - $w1 / 2, $y - $h + 1 + $i * $fh, $tmp[$i], $this->current_color);
690
                    }
691
                }
692
            } else {
693
                //Put the text
694
                imagestring($this->img, $use_font, $x, $y - $h + 1, $txt, $this->current_color);
695
            }
696
            if ($aDebug) {
697
                // Draw the bounding rectangle and the bounding box
698
                $p1 = [round($x), round($y), round($x), round($y - $h), round($x + $w), round($y - $h), round($x + $w), round($y)];
699
700
                // Draw bounding box
701
                $this->PushColor('green');
702
                $this->Polygon($p1, true);
703
                $this->PopColor();
704
            }
705
            $aBoundingBox = [round($x), round($y), round($x), round($y - $h), round($x + $w), round($y - $h), round($x + $w), round($y)];
706
        }
707
    }
708
709
    public function AddTxtCR($aTxt)
710
    {
711
        // If the user has just specified a '\n'
712
        // instead of '\n\t' we have to add '\r' since
713
        // the width will be too muchy otherwise since when
714
        // we print we stroke the individually lines by hand.
715
        $e = explode("\n", $aTxt);
716
        $n = count($e);
717
        for ($i = 0; $i < $n; ++$i) {
718
            $e[$i] = str_replace("\r", "", $e[$i]);
719
        }
720
        return implode("\n\r", $e);
721
    }
722
723
    public function NormAngle($a)
724
    {
725
        // Normalize angle in degrees
726
        // Normalize angle to be between 0-360
727
        while ($a > 360) {
728
            $a -= 360;
729
        }
730
731
        while ($a < -360) {
732
            $a += 360;
733
        }
734
735
        if ($a < 0) {
736
            $a = 360 + $a;
737
        }
738
739
        return $a;
740
    }
741
742
    public function imagettfbbox_fixed($size, $angle, $fontfile, $text)
743
    {
744
        if (!USE_LIBRARY_IMAGETTFBBOX) {
745
            $bbox = @imagettfbbox($size, $angle, $fontfile, $text);
746
            if ($bbox === false) {
747
                Util\JpGraphError::RaiseL(25092, $this->font_file);
748
                //("There is either a configuration problem with TrueType or a problem reading font file (".$this->font_file."). Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try uppgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library.");
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...
749
            }
750
            $this->bbox_cache = $bbox;
751
            return $bbox;
752
        }
753
754
        // The built in imagettfbbox is buggy for angles != 0 so
755
        // we calculate this manually by getting the bounding box at
756
        // angle = 0 and then rotate the bounding box manually
757
        $bbox = @imagettfbbox($size, 0, $fontfile, $text);
758
        if ($bbox === false) {
759
            Util\JpGraphError::RaiseL(25092, $this->font_file);
760
            //("There is either a configuration problem with TrueType or a problem reading font file (".$this->font_file."). Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try uppgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library.");
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...
761
        }
762
763
        $angle = $this->NormAngle($angle);
764
765
        $a   = $angle * M_PI / 180;
766
        $ca  = cos($a);
767
        $sa  = sin($a);
768
        $ret = [];
769
770
        // We always add 1 pixel to the left since the left edge of the bounding
771
        // box is sometimes coinciding with the first pixel of the text
772
        //$bbox[0] -= 1;
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...
773
        //$bbox[6] -= 1;
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...
774
775
        // For roatated text we need to add extra width for rotated
776
        // text since the kerning and stroking of the TTF is not the same as for
777
        // text at a 0 degree angle
778
779
        if ($angle > 0.001 && abs($angle - 360) > 0.001) {
780
            $h = abs($bbox[7] - $bbox[1]);
781
            $w = abs($bbox[2] - $bbox[0]);
782
783
            $bbox[0] -= 2;
784
            $bbox[6] -= 2;
785
            // The width is underestimated so compensate for that
786
            $bbox[2] += round($w * 0.06);
787
            $bbox[4] += round($w * 0.06);
788
789
            // and we also need to compensate with increased height
790
            $bbox[5] -= round($h * 0.1);
791
            $bbox[7] -= round($h * 0.1);
792
793
            if ($angle > 90) {
794
                // For angles > 90 we also need to extend the height further down
795
                // by the baseline since that is also one more problem
796
                $bbox[1] += round($h * 0.15);
797
                $bbox[3] += round($h * 0.15);
798
799
                // and also make it slighty less height
800
                $bbox[7] += round($h * 0.05);
801
                $bbox[5] += round($h * 0.05);
802
803
                // And we need to move the box slightly top the rright (from a tetx perspective)
804
                $bbox[0] += round($w * 0.02);
805
                $bbox[6] += round($w * 0.02);
806
807
                if ($angle > 180) {
808
                    // And we need to move the box slightly to the left (from a text perspective)
809
                    $bbox[0] -= round($w * 0.02);
810
                    $bbox[6] -= round($w * 0.02);
811
                    $bbox[2] -= round($w * 0.02);
812
                    $bbox[4] -= round($w * 0.02);
813
                }
814
            }
815
            for ($i = 0; $i < 7; $i += 2) {
816
                $ret[$i]     = round($bbox[$i] * $ca + $bbox[$i + 1] * $sa);
817
                $ret[$i + 1] = round($bbox[$i + 1] * $ca - $bbox[$i] * $sa);
818
            }
819
            $this->bbox_cache = $ret;
820
            return $ret;
821
        } else {
822
            $this->bbox_cache = $bbox;
823
            return $bbox;
824
        }
825
    }
826
827
    // Deprecated
828
    public function GetTTFBBox($aTxt, $aAngle = 0)
829
    {
830
        $bbox = $this->imagettfbbox_fixed($this->font_size, $aAngle, $this->font_file, $aTxt);
831
        return $bbox;
832
    }
833
834
    public function GetBBoxTTF($aTxt, $aAngle = 0)
835
    {
836
        // Normalize the bounding box to become a minimum
837
        // enscribing rectangle
838
839
        $aTxt = $this->AddTxtCR($aTxt);
840
841
        if (!is_readable($this->font_file)) {
842
            Util\JpGraphError::RaiseL(25093, $this->font_file);
843
            //('Can not read font file ('.$this->font_file.') in call to Image::GetBBoxTTF. Please make sure that you have set a font before calling this method and that the font is installed in the TTF directory.');
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...
844
        }
845
        $bbox = $this->imagettfbbox_fixed($this->font_size, $aAngle, $this->font_file, $aTxt);
846
847
        if ($aAngle == 0) {
848
            return $bbox;
849
        }
850
851
        if ($aAngle >= 0) {
852 View Code Duplication
            if ($aAngle <= 90) {
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...
853
                //<=0
854
                $bbox = [$bbox[6], $bbox[1], $bbox[2], $bbox[1],
855
                    $bbox[2], $bbox[5], $bbox[6], $bbox[5]];
856
            } elseif ($aAngle <= 180) {
857
                //<= 2
858
                $bbox = [$bbox[4], $bbox[7], $bbox[0], $bbox[7],
859
                    $bbox[0], $bbox[3], $bbox[4], $bbox[3]];
860
            } elseif ($aAngle <= 270) {
861
                //<= 3
862
                $bbox = [$bbox[2], $bbox[5], $bbox[6], $bbox[5],
863
                    $bbox[6], $bbox[1], $bbox[2], $bbox[1]];
864
            } else {
865
                $bbox = [$bbox[0], $bbox[3], $bbox[4], $bbox[3],
866
                    $bbox[4], $bbox[7], $bbox[0], $bbox[7]];
867
            }
868
        } elseif ($aAngle < 0) {
869 View Code Duplication
            if ($aAngle <= -270) {
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...
870
                // <= -3
871
                $bbox = [$bbox[6], $bbox[1], $bbox[2], $bbox[1],
872
                    $bbox[2], $bbox[5], $bbox[6], $bbox[5]];
873
            } elseif ($aAngle <= -180) {
874
                // <= -2
875
                $bbox = [$bbox[0], $bbox[3], $bbox[4], $bbox[3],
876
                    $bbox[4], $bbox[7], $bbox[0], $bbox[7]];
877
            } elseif ($aAngle <= -90) {
878
                // <= -1
879
                $bbox = [$bbox[2], $bbox[5], $bbox[6], $bbox[5],
880
                    $bbox[6], $bbox[1], $bbox[2], $bbox[1]];
881
            } else {
882
                $bbox = [$bbox[0], $bbox[3], $bbox[4], $bbox[3],
883
                    $bbox[4], $bbox[7], $bbox[0], $bbox[7]];
884
            }
885
        }
886
        return $bbox;
887
    }
888
889
    public function GetBBoxHeight($aTxt, $aAngle = 0)
890
    {
891
        $box = $this->GetBBoxTTF($aTxt, $aAngle);
892
        return abs($box[7] - $box[1]);
893
    }
894
895
    public function GetBBoxWidth($aTxt, $aAngle = 0)
896
    {
897
        $box = $this->GetBBoxTTF($aTxt, $aAngle);
898
        return $box[2] - $box[0] + 1;
899
    }
900
901
    public function _StrokeTTF($x, $y, $txt, $dir, $paragraph_align, &$aBoundingBox, $debug = false)
902
    {
903
904
        // Setup default inter line margin for paragraphs to be
905
        // 3% of the font height.
906
        $ConstLineSpacing = 0.03;
907
908
        // Remember the anchor point before adjustment
909
        if ($debug) {
910
            $ox = $x;
911
            $oy = $y;
912
        }
913
914
        if (!preg_match('/\n/', $txt) || ($dir > 0 && preg_match('/\n/', $txt))) {
915
            // Format a single line
916
917
            $txt    = $this->AddTxtCR($txt);
918
            $bbox   = $this->GetBBoxTTF($txt, $dir);
919
            $width  = $this->GetBBoxWidth($txt, $dir);
920
            $height = $this->GetBBoxHeight($txt, $dir);
921
922
            // The special alignment "basepoint" is mostly used internally
923
            // in the library. This will put the anchor position at the left
924
            // basepoint of the tetx. This is the default anchor point for
925
            // TTF text.
926
927
            if ($this->text_valign != 'basepoint') {
928
                // Align x,y ot lower left corner of bbox
929
930
                if ($this->text_halign == 'right') {
931
                    $x -= $width;
932
                    $x -= $bbox[0];
933
                } elseif ($this->text_halign == 'center') {
934
                    $x -= $width / 2;
935
                    $x -= $bbox[0];
936
                } elseif ($this->text_halign == 'baseline') {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
937
                    // This is only support for text at 90 degree !!
938
                    // Do nothing the text is drawn at baseline by default
939
                }
940
941
                if ($this->text_valign == 'top') {
942
                    $y -= $bbox[1]; // Adjust to bottom of text
943
                    $y += $height;
944
                } elseif ($this->text_valign == 'center') {
945
                    $y -= $bbox[1]; // Adjust to bottom of text
946
                    $y += $height / 2;
947
                } elseif ($this->text_valign == 'baseline') {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
948
                    // This is only support for text at 0 degree !!
949
                    // Do nothing the text is drawn at baseline by default
950
                }
951
            }
952
            ImageTTFText($this->img, $this->font_size, $dir, $x, $y,
953
                $this->current_color, $this->font_file, $txt);
954
955
            // Calculate and return the co-ordinates for the bounding box
956
            $box = $this->imagettfbbox_fixed($this->font_size, $dir, $this->font_file, $txt);
957
            $p1  = [];
958
959
            for ($i = 0; $i < 4; ++$i) {
960
                $p1[] = round($box[$i * 2] + $x);
961
                $p1[] = round($box[$i * 2 + 1] + $y);
962
            }
963
            $aBoundingBox = $p1;
964
965
            // Debugging code to highlight the bonding box and bounding rectangle
966
            // For text at 0 degrees the bounding box and bounding rectangle are the
967
            // same
968
            if ($debug) {
969
                // Draw the bounding rectangle and the bounding box
970
971
                $p  = [];
972
                $p1 = [];
973
974
                for ($i = 0; $i < 4; ++$i) {
975
                    $p[]  = $bbox[$i * 2] + $x;
976
                    $p[]  = $bbox[$i * 2 + 1] + $y;
977
                    $p1[] = $box[$i * 2] + $x;
978
                    $p1[] = $box[$i * 2 + 1] + $y;
979
                }
980
981
                // Draw bounding box
982
                $this->PushColor('green');
983
                $this->Polygon($p1, true);
984
                $this->PopColor();
985
986
                // Draw bounding rectangle
987
                $this->PushColor('darkgreen');
988
                $this->Polygon($p, true);
989
                $this->PopColor();
990
991
                // Draw a cross at the anchor point
992
                $this->PushColor('red');
993
                $this->Line($ox - 15, $oy, $ox + 15, $oy);
0 ignored issues
show
Bug introduced by
The variable $ox 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 $oy 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...
994
                $this->Line($ox, $oy - 15, $ox, $oy + 15);
995
                $this->PopColor();
996
            }
997
        } else {
998
            // Format a text paragraph
999
            $fh = $this->GetFontHeight();
1000
1001
            // Line margin is 25% of font height
1002
            $linemargin = round($fh * $ConstLineSpacing);
1003
            $fh += $linemargin;
1004
            $w = $this->GetTextWidth($txt);
1005
1006
            $y -= $linemargin / 2;
1007
            $tmp = preg_split('/\n/', $txt);
1008
            $nl  = count($tmp);
1009
            $h   = $nl * $fh;
1010
1011 View Code Duplication
            if ($this->text_halign == 'right') {
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...
1012
                $x -= $dir == 0 ? $w : $h;
1013
            } elseif ($this->text_halign == 'center') {
1014
                $x -= $dir == 0 ? $w / 2 : $h / 2;
1015
            }
1016
1017 View Code Duplication
            if ($this->text_valign == 'top') {
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...
1018
                $y += $dir == 0 ? $h : $w;
1019
            } elseif ($this->text_valign == 'center') {
1020
                $y += $dir == 0 ? $h / 2 : $w / 2;
1021
            }
1022
1023
            // Here comes a tricky bit.
1024
            // Since we have to give the position for the string at the
1025
            // baseline this means thaht text will move slightly up
1026
            // and down depending on any of it's character descend below
1027
            // the baseline, for example a 'g'. To adjust the Y-position
1028
            // we therefore adjust the text with the baseline Y-offset
1029
            // as used for the current font and size. This will keep the
1030
            // baseline at a fixed positoned disregarding the actual
1031
            // characters in the string.
1032
            $standardbox  = $this->GetTTFBBox('Gg', $dir);
1033
            $yadj         = $standardbox[1];
1034
            $xadj         = $standardbox[0];
0 ignored issues
show
Unused Code introduced by
$xadj 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...
1035
            $aBoundingBox = [];
1036
            for ($i = 0; $i < $nl; ++$i) {
1037
                $wl   = $this->GetTextWidth($tmp[$i]);
1038
                $bbox = $this->GetTTFBBox($tmp[$i], $dir);
1039
                if ($paragraph_align == 'left') {
1040
                    $xl = $x;
1041
                } elseif ($paragraph_align == 'right') {
1042
                    $xl = $x + ($w - $wl);
1043
                } else {
1044
                    // Center
1045
                    $xl = $x + $w / 2 - $wl / 2;
1046
                }
1047
1048
                // In theory we should adjust with full pre-lead to get the lines
1049
                // lined up but this doesn't look good so therfore we only adjust with
1050
                // half th pre-lead
1051
                $xl -= $bbox[0] / 2;
1052
                $yl = $y - $yadj;
1053
                //$xl = $xl- $xadj;
1 ignored issue
show
Unused Code Comprehensibility introduced by
45% 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...
1054
                ImageTTFText($this->img, $this->font_size, $dir, $xl, $yl - ($h - $fh) + $fh * $i,
1055
                    $this->current_color, $this->font_file, $tmp[$i]);
1056
1057
                // echo "xl=$xl,".$tmp[$i]." <br>";
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...
1058
                if ($debug) {
1059
                    // Draw the bounding rectangle around each line
1060
                    $box = @ImageTTFBBox($this->font_size, $dir, $this->font_file, $tmp[$i]);
0 ignored issues
show
Unused Code introduced by
$box 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...
1061
                    $p   = [];
1062
                    for ($j = 0; $j < 4; ++$j) {
1063
                        $p[] = $bbox[$j * 2] + $xl;
1064
                        $p[] = $bbox[$j * 2 + 1] + $yl - ($h - $fh) + $fh * $i;
1065
                    }
1066
1067
                    // Draw bounding rectangle
1068
                    $this->PushColor('darkgreen');
1069
                    $this->Polygon($p, true);
1070
                    $this->PopColor();
1071
                }
1072
            }
1073
1074
            // Get the bounding box
1075
            $bbox = $this->GetBBoxTTF($txt, $dir);
1076
            for ($j = 0; $j < 4; ++$j) {
1077
                $bbox[$j * 2] += round($x);
1078
                $bbox[$j * 2 + 1] += round($y - ($h - $fh) - $yadj);
1079
            }
1080
            $aBoundingBox = $bbox;
1081
1082
            if ($debug) {
1083
                // Draw a cross at the anchor point
1084
                $this->PushColor('red');
1085
                $this->Line($ox - 25, $oy, $ox + 25, $oy);
1086
                $this->Line($ox, $oy - 25, $ox, $oy + 25);
1087
                $this->PopColor();
1088
            }
1089
        }
1090
    }
1091
1092
    public function StrokeText($x, $y, $txt, $dir = 0, $paragraph_align = "left", $debug = false)
1093
    {
1094
        $x = round($x);
1095
        $y = round($y);
1096
1097
        // Do special language encoding
1098
        $txt = $this->langconv->Convert($txt, $this->font_family);
1099
1100
        if (!is_numeric($dir)) {
1101
            Util\JpGraphError::RaiseL(25094); //(" Direction for text most be given as an angle between 0 and 90.");
1102
        }
1103
1104
        if ($this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2 + 1) {
1105
            $this->_StrokeBuiltinFont($x, $y, $txt, $dir, $paragraph_align, $boundingbox, $debug);
1106
        } elseif ($this->font_family >= _FIRST_FONT && $this->font_family <= _LAST_FONT) {
1107
            $this->_StrokeTTF($x, $y, $txt, $dir, $paragraph_align, $boundingbox, $debug);
1108
        } else {
1109
            Util\JpGraphError::RaiseL(25095); //(" Unknown font font family specification. ");
1110
        }
1111
        return $boundingbox;
0 ignored issues
show
Bug introduced by
The variable $boundingbox 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...
1112
    }
1113
1114
    public function SetMargin($lm, $rm, $tm, $bm)
1115
    {
1116
        $this->left_margin   = $lm;
0 ignored issues
show
Bug introduced by
The property left_margin does not seem to exist. Did you mean _left_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...
1117
        $this->right_margin  = $rm;
0 ignored issues
show
Bug introduced by
The property right_margin does not seem to exist. Did you mean _right_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...
1118
        $this->top_margin    = $tm;
0 ignored issues
show
Bug introduced by
The property top_margin does not seem to exist. Did you mean _top_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...
1119
        $this->bottom_margin = $bm;
0 ignored issues
show
Bug introduced by
The property bottom_margin does not seem to exist. Did you mean _bottom_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...
1120
1121
        $this->plotwidth  = $this->width - $this->left_margin - $this->right_margin;
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property left_margin does not seem to exist. Did you mean _left_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...
Bug introduced by
The property right_margin does not seem to exist. Did you mean _right_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...
Documentation Bug introduced by
It seems like $this->width - $this->le...n - $this->right_margin can also be of type double. However, the property $plotwidth is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1122
        $this->plotheight = $this->height - $this->top_margin - $this->bottom_margin;
0 ignored issues
show
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
Bug introduced by
The property top_margin does not seem to exist. Did you mean _top_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...
Bug introduced by
The property bottom_margin does not seem to exist. Did you mean _bottom_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...
Documentation Bug introduced by
It seems like $this->height - $this->t... - $this->bottom_margin can also be of type double. However, the property $plotheight is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1123
1124
        if ($this->width > 0 && $this->height > 0) {
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
1125
            if ($this->plotwidth < 0 || $this->plotheight < 0) {
1126
                Util\JpGraphError::RaiseL(25130, $this->plotwidth, $this->plotheight);
1127
                //Util\JpGraphError::raise("To small plot area. ($lm,$rm,$tm,$bm : $this->plotwidth x $this->plotheight). With the given image size and margins there is to little space left for the plot. Increase the plot size or reduce the margins.");
1 ignored issue
show
Unused Code Comprehensibility introduced by
72% 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...
1128
            }
1129
        }
1130
    }
1131
1132
    public function SetTransparent($color)
1133
    {
1134
        imagecolortransparent($this->img, $this->rgb->allocate($color));
1135
    }
1136
1137
    public function SetColor($color, $aAlpha = 0)
1138
    {
1139
        $this->current_color_name = $color;
1140
        $this->current_color      = $this->rgb->allocate($color, $aAlpha);
1141
        if ($this->current_color == -1) {
1142
            $tc = imagecolorstotal($this->img);
0 ignored issues
show
Unused Code introduced by
$tc 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...
1143
            Util\JpGraphError::RaiseL(25096);
1144
            //("Can't allocate any more colors. Image has already allocated maximum of <b>$tc colors</b>. This might happen if you have anti-aliasing turned on together with a background image or perhaps gradient fill since this requires many, many colors. Try to turn off anti-aliasing. If there is still a problem try downgrading the quality of the background image to use a smaller pallete to leave some entries for your graphs. You should try to limit the number of colors in your background image to 64. If there is still problem set the constant DEFINE(\"USE_APPROX_COLORS\",true); in jpgraph.php This will use approximative colors when the palette is full. Unfortunately there is not much JpGraph can do about this since the palette size is a limitation of current graphic format and what the underlying GD library suppports.");
1 ignored issue
show
Unused Code Comprehensibility introduced by
84% 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...
1145
        }
1146
        return $this->current_color;
1147
    }
1148
1149
    public function PushColor($color)
1150
    {
1151
        if ($color != "") {
1152
            $this->colorstack[$this->colorstackidx]     = $this->current_color_name;
1153
            $this->colorstack[$this->colorstackidx + 1] = $this->current_color;
1154
            $this->colorstackidx += 2;
1155
            $this->SetColor($color);
1156
        } else {
1157
            Util\JpGraphError::RaiseL(25097); //("Color specified as empty string in PushColor().");
1158
        }
1159
    }
1160
1161
    public function PopColor()
1162
    {
1163
        if ($this->colorstackidx < 1) {
1164
            Util\JpGraphError::RaiseL(25098); //(" Negative Color stack index. Unmatched call to PopColor()");
1165
        }
1166
        $this->current_color      = $this->colorstack[--$this->colorstackidx];
1167
        $this->current_color_name = $this->colorstack[--$this->colorstackidx];
1168
    }
1169
1170
    public function SetLineWeight($weight)
1171
    {
1172
        $old = $this->line_weight;
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1173
        imagesetthickness($this->img, $weight);
1174
        $this->line_weight = $weight;
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1175
        return $old;
1176
    }
1177
1178
    public function SetStartPoint($x, $y)
1179
    {
1180
        $this->lastx = round($x);
0 ignored issues
show
Documentation Bug introduced by
The property $lastx was declared of type integer, but round($x) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1181
        $this->lasty = round($y);
0 ignored issues
show
Documentation Bug introduced by
The property $lasty was declared of type integer, but round($y) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1182
    }
1183
1184
    public function Arc($cx, $cy, $w, $h, $s, $e)
1185
    {
1186
        // GD Arc doesn't like negative angles
1187
        while ($s < 0) {
1188
            $s += 360;
1189
        }
1190
1191
        while ($e < 0) {
1192
            $e += 360;
1193
        }
1194
1195
        imagearc($this->img, round($cx), round($cy), round($w), round($h), $s, $e, $this->current_color);
1196
    }
1197
1198
    public function FilledArc($xc, $yc, $w, $h, $s, $e, $style = '')
1199
    {
1200
        $s = round($s);
1201
        $e = round($e);
1202
        while ($s < 0) {
1203
            $s += 360;
1204
        }
1205
1206
        while ($e < 0) {
1207
            $e += 360;
1208
        }
1209
1210
        if ($style == '') {
1211
            $style = IMG_ARC_PIE;
1212
        }
1213
1214
        if (abs($s - $e) > 0) {
1215
            imagefilledarc($this->img, round($xc), round($yc), round($w), round($h), $s, $e, $this->current_color, $style);
1216
            //            $this->DrawImageSmoothArc($this->img,round($xc),round($yc),round($w),round($h),$s,$e,$this->current_color,$style);
1 ignored issue
show
Unused Code Comprehensibility introduced by
80% 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...
1217
        }
1218
    }
1219
1220
    public function FilledCakeSlice($cx, $cy, $w, $h, $s, $e)
1221
    {
1222
        $this->CakeSlice($cx, $cy, $w, $h, $s, $e, $this->current_color_name);
1223
    }
1224
1225
    public function CakeSlice($xc, $yc, $w, $h, $s, $e, $fillcolor = "", $arccolor = "")
1226
    {
1227
        $s  = round($s);
1228
        $e  = round($e);
1229
        $w  = round($w);
1230
        $h  = round($h);
1231
        $xc = round($xc);
1232
        $yc = round($yc);
1233
        if ($s == $e) {
1234
            // A full circle. We draw this a plain circle
1235
            $this->PushColor($fillcolor);
1236
            imagefilledellipse($this->img, $xc, $yc, 2 * $w, 2 * $h, $this->current_color);
1237
1238
            // If antialiasing is used then we often don't have any color no the surrounding
1239
            // arc. So, we need to check for this special case so we don't send an empty
1240
            // color to the push function. In this case we use the fill color for the arc as well
1241
            if ($arccolor != '') {
1242
                $this->PopColor();
1243
                $this->PushColor($arccolor);
1244
            }
1245
            imageellipse($this->img, $xc, $yc, 2 * $w, 2 * $h, $this->current_color);
1246
            $this->Line($xc, $yc, cos($s * M_PI / 180) * $w + $xc, $yc + sin($s * M_PI / 180) * $h);
1247
            $this->PopColor();
1248
        } else {
1249
            $this->PushColor($fillcolor);
1250
            $this->FilledArc($xc, $yc, 2 * $w, 2 * $h, $s, $e);
1251
            $this->PopColor();
1252
            if ($arccolor != "") {
1253
                $this->PushColor($arccolor);
1254
                // We add 2 pixels to make the Arc() better aligned with
1255
                // the filled arc.
1256
                imagefilledarc($this->img, $xc, $yc, 2 * $w, 2 * $h, $s, $e, $this->current_color, IMG_ARC_NOFILL | IMG_ARC_EDGED);
1257
                $this->PopColor();
1258
            }
1259
        }
1260
    }
1261
1262
    public function Ellipse($xc, $yc, $w, $h)
1263
    {
1264
        $this->Arc($xc, $yc, $w, $h, 0, 360);
1265
    }
1266
1267
    public function Circle($xc, $yc, $r)
1268
    {
1269
        imageellipse($this->img, round($xc), round($yc), $r * 2, $r * 2, $this->current_color);
1270
        //        $this->DrawImageSmoothArc($this->img,round($xc),round($yc),$r*2+1,$r*2+1,0,360,$this->current_color);
1 ignored issue
show
Unused Code Comprehensibility introduced by
75% 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...
1271
        //        $this->imageSmoothCircle($this->img, round($xc),round($yc), $r*2+1, $this->current_color);
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...
1272
    }
1273
1274
    public function FilledCircle($xc, $yc, $r)
1275
    {
1276
        imagefilledellipse($this->img, round($xc), round($yc), 2 * $r, 2 * $r, $this->current_color);
1277
        //        $this->DrawImageSmoothArc($this->img, round($xc), round($yc), 2*$r, 2*$r, 0, 360, $this->current_color);
1 ignored issue
show
Unused Code Comprehensibility introduced by
66% 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...
1278
    }
1279
1280
    // Linear Color InterPolation
1281
    public function lip($f, $t, $p)
1282
    {
1283
        $p = round($p, 1);
1284
        $r = $f[0] + ($t[0] - $f[0]) * $p;
1285
        $g = $f[1] + ($t[1] - $f[1]) * $p;
1286
        $b = $f[2] + ($t[2] - $f[2]) * $p;
1287
        return [$r, $g, $b];
1288
    }
1289
1290
    // Set line style dashed, dotted etc
1291
    public function SetLineStyle($s)
1292
    {
1293
        if (is_numeric($s)) {
1294
            if ($s < 1 || $s > 4) {
1295
                Util\JpGraphError::RaiseL(25101, $s); //(" Illegal numeric argument to SetLineStyle(): ($s)");
1296
            }
1297
        } elseif (is_string($s)) {
1298
            if ($s == "solid") {
1299
                $s = 1;
1300
            } elseif ($s == "dotted") {
1301
                $s = 2;
1302
            } elseif ($s == "dashed") {
1303
                $s = 3;
1304
            } elseif ($s == "longdashed") {
1305
                $s = 4;
1306
            } else {
1307
                Util\JpGraphError::RaiseL(25102, $s); //(" Illegal string argument to SetLineStyle(): $s");
1308
            }
1309
        } else {
1310
            Util\JpGraphError::RaiseL(25103, $s); //(" Illegal argument to SetLineStyle $s");
1311
        }
1312
        $old              = $this->line_style;
1313
        $this->line_style = $s;
1314
        return $old;
1315
    }
1316
1317
    // Same as Line but take the line_style into account
1318
    public function StyleLine($x1, $y1, $x2, $y2, $aStyle = '', $from_grid_class = false)
1319
    {
1320
        if ($this->line_weight <= 0) {
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1321
            return;
1322
        }
1323
1324
        if ($aStyle === '') {
1325
            $aStyle = $this->line_style;
1326
        }
1327
1328
        $dashed_line_method = 'DashedLine';
1329
        if ($from_grid_class) {
1330
            $dashed_line_method = 'DashedLineForGrid';
1331
        }
1332
1333
        // Add error check since dashed line will only work if anti-alias is disabled
1334
        // this is a limitation in GD
1335
1336
        if ($aStyle == 1) {
1337
            // Solid style. We can handle anti-aliasing for this
1338
            $this->Line($x1, $y1, $x2, $y2);
1339
        } else {
1340
            // Since the GD routines doesn't handle AA for styled line
1341
            // we have no option than to turn it off to get any lines at
1342
            // all if the weight > 1
1343
            $oldaa = $this->GetAntiAliasing();
1344
            if ($oldaa && $this->line_weight > 1) {
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1345
                $this->SetAntiAliasing(false);
1346
            }
1347
1348
            switch ($aStyle) {
1349
                case 2: // Dotted
1350
                    $this->$dashed_line_method($x1, $y1, $x2, $y2, 2, 6);
1351
                    break;
1352
                case 3: // Dashed
1353
                    $this->$dashed_line_method($x1, $y1, $x2, $y2, 5, 9);
1354
                    break;
1355
                case 4: // Longdashes
1356
                    $this->$dashed_line_method($x1, $y1, $x2, $y2, 9, 13);
1357
                    break;
1358
                default:
1359
                    Util\JpGraphError::RaiseL(25104, $this->line_style); //(" Unknown line style: $this->line_style ");
1360
                    break;
1361
            }
1362
            if ($oldaa) {
1363
                $this->SetAntiAliasing(true);
1364
            }
1365
        }
1366
    }
1367
1368
    public function DashedLine($x1, $y1, $x2, $y2, $dash_length = 1, $dash_space = 4)
1369
    {
1370
        if ($this->line_weight <= 0) {
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1371
            return;
1372
        }
1373
1374
        // Add error check to make sure anti-alias is not enabled.
1375
        // Dashed line does not work with anti-alias enabled. This
1376
        // is a limitation in GD.
1377
        if ($this->use_anti_aliasing) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1378
            //            Util\JpGraphError::RaiseL(25129); // Anti-alias can not be used with dashed lines. Please disable anti-alias or use solid lines.
1 ignored issue
show
Unused Code Comprehensibility introduced by
56% 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...
1379
        }
1380
1381
        $x1 = round($x1);
1382
        $x2 = round($x2);
1383
        $y1 = round($y1);
1384
        $y2 = round($y2);
1385
1386
        $dash_length *= SUPERSAMPLING_SCALE;
1387
        $dash_space *= SUPERSAMPLING_SCALE;
1388
1389
        $style = array_fill(0, $dash_length, $this->current_color);
1390
        $style = array_pad($style, $dash_space, IMG_COLOR_TRANSPARENT);
1391
        imagesetstyle($this->img, $style);
1392
        imageline($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
1393
1394
        $this->lastx = $x2;
0 ignored issues
show
Documentation Bug introduced by
The property $lastx was declared of type integer, but $x2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1395
        $this->lasty = $y2;
0 ignored issues
show
Documentation Bug introduced by
The property $lasty was declared of type integer, but $y2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1396
    }
1397
1398
    public function DashedLineForGrid($x1, $y1, $x2, $y2, $dash_length = 1, $dash_space = 4)
0 ignored issues
show
Unused Code introduced by
The parameter $dash_length is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1399
    {
1400
        if ($this->line_weight <= 0) {
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1401
            return;
1402
        }
1403
1404
        // Add error check to make sure anti-alias is not enabled.
1405
        // Dashed line does not work with anti-alias enabled. This
1406
        // is a limitation in GD.
1407
        if ($this->use_anti_aliasing) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1408
            //            Util\JpGraphError::RaiseL(25129); // Anti-alias can not be used with dashed lines. Please disable anti-alias or use solid lines.
1 ignored issue
show
Unused Code Comprehensibility introduced by
56% 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...
1409
        }
1410
1411
        $x1 = round($x1);
1412
        $x2 = round($x2);
1413
        $y1 = round($y1);
1414
        $y2 = round($y2);
1415
1416
        /*
1 ignored issue
show
Unused Code Comprehensibility introduced by
45% 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...
1417
        $dash_length *= $this->scale;
1418
        $dash_space  *= $this->scale;
1419
         */
1420
1421
        $dash_length = 2;
0 ignored issues
show
Unused Code introduced by
$dash_length 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...
1422
        $dash_length = 4;
1423
        imagesetthickness($this->img, 1);
1424
        $style = array_fill(0, $dash_length, $this->current_color); //hexdec('CCCCCC'));
1 ignored issue
show
Unused Code Comprehensibility introduced by
84% 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...
1425
        $style = array_pad($style, $dash_space, IMG_COLOR_TRANSPARENT);
1426
        imagesetstyle($this->img, $style);
1427
        imageline($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
1428
1429
        $this->lastx = $x2;
0 ignored issues
show
Documentation Bug introduced by
The property $lastx was declared of type integer, but $x2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1430
        $this->lasty = $y2;
0 ignored issues
show
Documentation Bug introduced by
The property $lasty was declared of type integer, but $y2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1431
    }
1432
1433
    public function Line($x1, $y1, $x2, $y2)
1434
    {
1435
        if ($this->line_weight <= 0) {
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1436
            return;
1437
        }
1438
1439
        $x1 = round($x1);
1440
        $x2 = round($x2);
1441
        $y1 = round($y1);
1442
        $y2 = round($y2);
1443
1444
        imageline($this->img, $x1, $y1, $x2, $y2, $this->current_color);
1445
        //        $this->DrawLine($this->img, $x1, $y1, $x2, $y2, $this->line_weight, $this->current_color);
1 ignored issue
show
Unused Code Comprehensibility introduced by
66% 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...
1446
        $this->lastx = $x2;
0 ignored issues
show
Documentation Bug introduced by
The property $lastx was declared of type integer, but $x2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1447
        $this->lasty = $y2;
0 ignored issues
show
Documentation Bug introduced by
The property $lasty was declared of type integer, but $y2 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1448
    }
1449
1450
    public function Polygon($p, $closed = false, $fast = false)
1451
    {
1452
        if ($this->line_weight <= 0) {
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1453
            return;
1454
        }
1455
1456
        $n    = count($p);
1457
        $oldx = $p[0];
1458
        $oldy = $p[1];
1459
        if ($fast) {
1460
            for ($i = 2; $i < $n; $i += 2) {
1461
                imageline($this->img, $oldx, $oldy, $p[$i], $p[$i + 1], $this->current_color);
1462
                $oldx = $p[$i];
1463
                $oldy = $p[$i + 1];
1464
            }
1465
            if ($closed) {
1466
                imageline($this->img, $p[$n * 2 - 2], $p[$n * 2 - 1], $p[0], $p[1], $this->current_color);
1467
            }
1468
        } else {
1469 View Code Duplication
            for ($i = 2; $i < $n; $i += 2) {
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...
1470
                $this->StyleLine($oldx, $oldy, $p[$i], $p[$i + 1]);
1471
                $oldx = $p[$i];
1472
                $oldy = $p[$i + 1];
1473
            }
1474
            if ($closed) {
1475
                $this->StyleLine($oldx, $oldy, $p[0], $p[1]);
1476
            }
1477
        }
1478
    }
1479
1480
    public function FilledPolygon($pts)
1481
    {
1482
        $n = count($pts);
1483
        if ($n == 0) {
1484
            Util\JpGraphError::RaiseL(25105); //('NULL data specified for a filled polygon. Check that your data is not NULL.');
1485
        }
1486
        for ($i = 0; $i < $n; ++$i) {
1487
            $pts[$i] = round($pts[$i]);
1488
        }
1489
        $old = $this->line_weight;
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1490
        imagesetthickness($this->img, 1);
1491
        imagefilledpolygon($this->img, $pts, count($pts) / 2, $this->current_color);
1492
        $this->line_weight = $old;
0 ignored issues
show
Bug introduced by
The property line_weight does not seem to exist. Did you mean _line_weight?

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...
1493
        imagesetthickness($this->img, $old);
1494
    }
1495
1496
    public function Rectangle($xl, $yu, $xr, $yl)
1497
    {
1498
        $this->Polygon([$xl, $yu, $xr, $yu, $xr, $yl, $xl, $yl, $xl, $yu]);
1499
    }
1500
1501
    public function FilledRectangle($xl, $yu, $xr, $yl)
1502
    {
1503
        $this->FilledPolygon([$xl, $yu, $xr, $yu, $xr, $yl, $xl, $yl]);
1504
    }
1505
1506
    public function FilledRectangle2($xl, $yu, $xr, $yl, $color1, $color2, $style = 1)
1507
    {
1508
        // Fill a rectangle with lines of two colors
1509
        if ($style === 1) {
1510
            // Horizontal stripe
1511
            if ($yl < $yu) {
1512
                $t  = $yl;
1513
                $yl = $yu;
1514
                $yu = $t;
1515
            }
1516 View Code Duplication
            for ($y = $yu; $y <= $yl; ++$y) {
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...
1517
                $this->SetColor($color1);
1518
                $this->Line($xl, $y, $xr, $y);
1519
                ++$y;
1520
                $this->SetColor($color2);
1521
                $this->Line($xl, $y, $xr, $y);
1522
            }
1523
        } else {
1524
            if ($xl < $xl) {
1525
                $t  = $xl;
1526
                $xl = $xr;
1527
                $xr = $t;
1528
            }
1529 View Code Duplication
            for ($x = $xl; $x <= $xr; ++$x) {
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...
1530
                $this->SetColor($color1);
1531
                $this->Line($x, $yu, $x, $yl);
1532
                ++$x;
1533
                $this->SetColor($color2);
1534
                $this->Line($x, $yu, $x, $yl);
1535
            }
1536
        }
1537
    }
1538
1539
    public function ShadowRectangle($xl, $yu, $xr, $yl, $fcolor = false, $shadow_width = 4, $shadow_color = 'darkgray', $useAlpha = true)
1540
    {
1541
        // This is complicated by the fact that we must also handle the case where
1542
        // the reactangle has no fill color
1543
        $xl = floor($xl);
1544
        $yu = floor($yu);
1545
        $xr = floor($xr);
1546
        $yl = floor($yl);
1547
        $this->PushColor($shadow_color);
1548
        $shadowAlpha = 0;
1549
        $this->SetLineWeight(1);
1550
        $this->SetLineStyle('solid');
1551
        $basecolor    = $this->rgb->Color($shadow_color);
1552
        $shadow_color = [$basecolor[0], $basecolor[1], $basecolor[2]];
1553
        for ($i = 0; $i < $shadow_width; ++$i) {
1554
            $this->SetColor($shadow_color, $shadowAlpha);
1555
            $this->Line($xr - $shadow_width + $i, $yu + $shadow_width,
1556
                $xr - $shadow_width + $i, $yl - $shadow_width - 1 + $i);
1557
            $this->Line($xl + $shadow_width, $yl - $shadow_width + $i,
1558
                $xr - $shadow_width + $i, $yl - $shadow_width + $i);
1559
            if ($useAlpha) {
1560
                $shadowAlpha += 1.0 / $shadow_width;
1561
            }
1562
        }
1563
1564
        $this->PopColor();
1565
        if ($fcolor == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1566
            $this->Rectangle($xl, $yu, $xr - $shadow_width - 1, $yl - $shadow_width - 1);
1567
        } else {
1568
            $this->PushColor($fcolor);
1569
            $this->FilledRectangle($xl, $yu, $xr - $shadow_width - 1, $yl - $shadow_width - 1);
1570
            $this->PopColor();
1571
            $this->Rectangle($xl, $yu, $xr - $shadow_width - 1, $yl - $shadow_width - 1);
1572
        }
1573
    }
1574
1575
    public function FilledRoundedRectangle($xt, $yt, $xr, $yl, $r = 5)
1576
    {
1577
        if ($r == 0) {
1578
            $this->FilledRectangle($xt, $yt, $xr, $yl);
1579
            return;
1580
        }
1581
1582
        // To avoid overlapping fillings (which will look strange
1583
        // when alphablending is enabled) we have no choice but
1584
        // to fill the five distinct areas one by one.
1585
1586
        // Center square
1587
        $this->FilledRectangle($xt + $r, $yt + $r, $xr - $r, $yl - $r);
1588
        // Top band
1589
        $this->FilledRectangle($xt + $r, $yt, $xr - $r, $yt + $r);
1590
        // Bottom band
1591
        $this->FilledRectangle($xt + $r, $yl - $r, $xr - $r, $yl);
1592
        // Left band
1593
        $this->FilledRectangle($xt, $yt + $r, $xt + $r, $yl - $r);
1594
        // Right band
1595
        $this->FilledRectangle($xr - $r, $yt + $r, $xr, $yl - $r);
1596
1597
        // Topleft & Topright arc
1598
        $this->FilledArc($xt + $r, $yt + $r, $r * 2, $r * 2, 180, 270);
1599
        $this->FilledArc($xr - $r, $yt + $r, $r * 2, $r * 2, 270, 360);
1600
1601
        // Bottomleft & Bottom right arc
1602
        $this->FilledArc($xt + $r, $yl - $r, $r * 2, $r * 2, 90, 180);
1603
        $this->FilledArc($xr - $r, $yl - $r, $r * 2, $r * 2, 0, 90);
1604
    }
1605
1606
    public function RoundedRectangle($xt, $yt, $xr, $yl, $r = 5)
1607
    {
1608
        if ($r == 0) {
1609
            $this->Rectangle($xt, $yt, $xr, $yl);
1610
            return;
1611
        }
1612
1613
        // Top & Bottom line
1614
        $this->Line($xt + $r, $yt, $xr - $r, $yt);
1615
        $this->Line($xt + $r, $yl, $xr - $r, $yl);
1616
1617
        // Left & Right line
1618
        $this->Line($xt, $yt + $r, $xt, $yl - $r);
1619
        $this->Line($xr, $yt + $r, $xr, $yl - $r);
1620
1621
        // Topleft & Topright arc
1622
        $this->Arc($xt + $r, $yt + $r, $r * 2, $r * 2, 180, 270);
1623
        $this->Arc($xr - $r, $yt + $r, $r * 2, $r * 2, 270, 360);
1624
1625
        // Bottomleft & Bottomright arc
1626
        $this->Arc($xt + $r, $yl - $r, $r * 2, $r * 2, 90, 180);
1627
        $this->Arc($xr - $r, $yl - $r, $r * 2, $r * 2, 0, 90);
1628
    }
1629
1630
    public function FilledBevel($x1, $y1, $x2, $y2, $depth = 2, $color1 = '[email protected]', $color2 = '[email protected]')
1631
    {
1632
        $this->FilledRectangle($x1, $y1, $x2, $y2);
1633
        $this->Bevel($x1, $y1, $x2, $y2, $depth, $color1, $color2);
1634
    }
1635
1636
    public function Bevel($x1, $y1, $x2, $y2, $depth = 2, $color1 = '[email protected]', $color2 = '[email protected]')
1637
    {
1638
        $this->PushColor($color1);
1639
        for ($i = 0; $i < $depth; ++$i) {
1640
            $this->Line($x1 + $i, $y1 + $i, $x1 + $i, $y2 - $i);
1641
            $this->Line($x1 + $i, $y1 + $i, $x2 - $i, $y1 + $i);
1642
        }
1643
        $this->PopColor();
1644
1645
        $this->PushColor($color2);
1646
        for ($i = 0; $i < $depth; ++$i) {
1647
            $this->Line($x1 + $i, $y2 - $i, $x2 - $i, $y2 - $i);
1648
            $this->Line($x2 - $i, $y1 + $i, $x2 - $i, $y2 - $i - 1);
1649
        }
1650
        $this->PopColor();
1651
    }
1652
1653
    public function StyleLineTo($x, $y)
1654
    {
1655
        $this->StyleLine($this->lastx, $this->lasty, $x, $y);
1656
        $this->lastx = $x;
1657
        $this->lasty = $y;
1658
    }
1659
1660
    public function LineTo($x, $y)
1661
    {
1662
        $this->Line($this->lastx, $this->lasty, $x, $y);
1663
        $this->lastx = $x;
1664
        $this->lasty = $y;
1665
    }
1666
1667
    public function Point($x, $y)
1668
    {
1669
        imagesetpixel($this->img, round($x), round($y), $this->current_color);
1670
    }
1671
1672
    public function Fill($x, $y)
1673
    {
1674
        imagefill($this->img, round($x), round($y), $this->current_color);
1675
    }
1676
1677
    public function FillToBorder($x, $y, $aBordColor)
1678
    {
1679
        $bc = $this->rgb->allocate($aBordColor);
1680
        if ($bc == -1) {
1681
            Util\JpGraphError::RaiseL(25106); //('Image::FillToBorder : Can not allocate more colors');
1682
        }
1683
        imagefilltoborder($this->img, round($x), round($y), $bc, $this->current_color);
1684
    }
1685
1686
    public function SetExpired($aFlg = true)
1687
    {
1688
        $this->expired = $aFlg;
1689
    }
1690
1691
    // Generate image header
1692
    public function Headers()
1693
    {
1694
1695
        // In case we are running from the command line with the client version of
1696
        // PHP we can't send any headers.
1697
        $sapi = php_sapi_name();
1698
        if ($sapi == 'cli') {
1699
            return;
1700
        }
1701
1702
        // These parameters are set by headers_sent() but they might cause
1703
        // an undefined variable error unless they are initilized
1704
        $file   = '';
1705
        $lineno = '';
1706
        if (headers_sent($file, $lineno)) {
1707
            $file = basename($file);
1708
            $t    = new ErrMsgText();
1709
            $msg  = $t->Get(10, $file, $lineno);
1710
            die($msg);
0 ignored issues
show
Coding Style Compatibility introduced by
The method Headers() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1711
        }
1712
1713
        if ($this->expired) {
1714
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
1715
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
1716
            header("Cache-Control: no-cache, must-revalidate");
1717
            header("Pragma: no-cache");
1718
        }
1719
        header("Content-type: image/$this->img_format");
1720
    }
1721
1722
    // Adjust image quality for formats that allow this
1723
    public function SetQuality($q)
1724
    {
1725
        $this->quality = $q;
1726
    }
1727
1728
    // Stream image to browser or to file
1729
    public function Stream($aFile = "")
1730
    {
1731
        $this->DoSupersampling();
1732
1733
        $func = "image" . $this->img_format;
1734
        if ($this->img_format == "jpeg" && $this->quality != null) {
1735
            $res = @$func($this->img, $aFile, $this->quality);
0 ignored issues
show
Unused Code introduced by
$res 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...
1736
        } else {
1737
            if ($aFile != "") {
1738
                $res = @$func($this->img, $aFile);
1739
                if (!$res) {
1740
                    Util\JpGraphError::RaiseL(25107, $aFile); //("Can't write to file '$aFile'. Check that the process running PHP has enough permission.");
1741
                }
1742
            } else {
1743
                $res = @$func($this->img);
1744
                if (!$res) {
1745
                    Util\JpGraphError::RaiseL(25108); //("Can't stream image. This is most likely due to a faulty PHP/GD setup. Try to recompile PHP and use the built-in GD library that comes with PHP.");
1746
                }
1747
            }
1748
        }
1749
    }
1750
1751
    // Do SuperSampling using $scale
1752
    public function DoSupersampling()
1753
    {
1754
        if (SUPERSAMPLING_SCALE <= 1) {
1755
            return $this->img;
1756
        }
1757
1758
        $dst_img = @imagecreatetruecolor($this->original_width, $this->original_height);
1759
        imagecopyresampled($dst_img, $this->img, 0, 0, 0, 0, $this->original_width, $this->original_height, $this->width, $this->height);
0 ignored issues
show
Bug introduced by
The property width does not seem to exist. Did you mean _width?

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...
Bug introduced by
The property height does not seem to exist. Did you mean original_height?

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...
1760
        $this->Destroy();
1761
        return $this->img = $dst_img;
1762
    }
1763
1764
    // Clear resources used by image (this is normally not used since all resources are/should be
1765
    // returned when the script terminates
1766
    public function Destroy()
1767
    {
1768
        imagedestroy($this->img);
1769
    }
1770
1771
    // Specify image format. Note depending on your installation
1772
    // of PHP not all formats may be supported.
1773
    public function SetImgFormat($aFormat, $aQuality = 75)
1774
    {
1775
        $this->quality = $aQuality;
1776
        $aFormat       = strtolower($aFormat);
1777
        $tst           = true;
0 ignored issues
show
Unused Code introduced by
$tst 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...
1778
        $supported     = imagetypes();
1779
        if ($aFormat == "auto") {
1780
            if ($supported & IMG_PNG) {
1781
                $this->img_format = "png";
1782
            } elseif ($supported & IMG_JPG) {
1783
                $this->img_format = "jpeg";
1784
            } elseif ($supported & IMG_GIF) {
1785
                $this->img_format = "gif";
1786
            } elseif ($supported & IMG_WBMP) {
1787
                $this->img_format = "wbmp";
1788
            } elseif ($supported & IMG_XPM) {
1789
                $this->img_format = "xpm";
1790
            } else {
1791
                Util\JpGraphError::RaiseL(25109); //("Your PHP (and GD-lib) installation does not appear to support any known graphic formats. You need to first make sure GD is compiled as a module to PHP. If you also want to use JPEG images you must get the JPEG library. Please see the PHP docs for details.");
1792
            }
1793
            return true;
1794
        } else {
1795
            if ($aFormat == "jpeg" || $aFormat == "png" || $aFormat == "gif") {
1796
                if ($aFormat == "jpeg" && !($supported & IMG_JPG)) {
1797
                    $tst = false;
1798
                } elseif ($aFormat == "png" && !($supported & IMG_PNG)) {
1799
                    $tst = false;
1800
                } elseif ($aFormat == "gif" && !($supported & IMG_GIF)) {
1801
                    $tst = false;
1802
                } elseif ($aFormat == "wbmp" && !($supported & IMG_WBMP)) {
1803
                    $tst = false;
1804
                } elseif ($aFormat == "xpm" && !($supported & IMG_XPM)) {
1805
                    $tst = false;
1806
                } else {
1807
                    $this->img_format = $aFormat;
1808
                    return true;
1809
                }
1810
            } else {
1811
                $tst = false;
1812
            }
1813
            if (!$tst) {
1814
                Util\JpGraphError::RaiseL(25110, $aFormat); //(" Your PHP installation does not support the chosen graphic format: $aFormat");
1815
            }
1816
        }
1817
    }
1818
1819
    /**
1820
     * Draw Line
1821
     */
1822
    public function DrawLine($im, $x1, $y1, $x2, $y2, $weight, $color)
1823
    {
1824
        if ($weight == 1) {
1825
            return imageline($im, $x1, $y1, $x2, $y2, $color);
1826
        }
1827
1828
        $angle = (atan2(($y1 - $y2), ($x2 - $x1)));
1829
1830
        $dist_x = $weight * (sin($angle)) / 2;
1831
        $dist_y = $weight * (cos($angle)) / 2;
1832
1833
        $p1x = ceil(($x1 + $dist_x));
1834
        $p1y = ceil(($y1 + $dist_y));
1835
        $p2x = ceil(($x2 + $dist_x));
1836
        $p2y = ceil(($y2 + $dist_y));
1837
        $p3x = ceil(($x2 - $dist_x));
1838
        $p3y = ceil(($y2 - $dist_y));
1839
        $p4x = ceil(($x1 - $dist_x));
1840
        $p4y = ceil(($y1 - $dist_y));
1841
1842
        $array = [$p1x, $p1y, $p2x, $p2y, $p3x, $p3y, $p4x, $p4y];
1843
        imagefilledpolygon($im, $array, (count($array) / 2), $color);
1844
1845
        // for antialias
1846
        imageline($im, $p1x, $p1y, $p2x, $p2y, $color);
1847
        imageline($im, $p3x, $p3y, $p4x, $p4y, $color);
1848
        return;
1849
1850
        return imageline($this->img, $x1, $y1, $x2, $y2, $this->current_color);
0 ignored issues
show
Unused Code introduced by
return imageline($this->... $this->current_color); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
1851
        $weight = 8;
0 ignored issues
show
Unused Code introduced by
$weight = 8; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
1852
        if ($weight <= 1) {
1853
            return imageline($this->img, $x1, $y1, $x2, $y2, $this->current_color);
1854
        }
1855
1856
        $pts = [];
0 ignored issues
show
Unused Code introduced by
$pts 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...
1857
1858
        $weight /= 2;
1859
1860
        if ($y2 - $y1 == 0) {
1861
            // x line
1862
            $pts   = [];
1863
            $pts[] = $x1;
1864
            $pts[] = $y1 - $weight;
1865
            $pts[] = $x1;
1866
            $pts[] = $y1 + $weight;
1867
            $pts[] = $x2;
1868
            $pts[] = $y2 + $weight;
1869
            $pts[] = $x2;
1870
            $pts[] = $y2 - $weight;
1871
        } elseif ($x2 - $x1 == 0) {
1872
            // y line
1873
            $pts   = [];
1874
            $pts[] = $x1 - $weight;
1875
            $pts[] = $y1;
1876
            $pts[] = $x1 + $weight;
1877
            $pts[] = $y1;
1878
            $pts[] = $x2 + $weight;
1879
            $pts[] = $y2;
1880
            $pts[] = $x2 - $weight;
1881
            $pts[] = $y2;
1882
        } else {
1883
            $length = sqrt(pow($x2 - $x1, 2) + pow($y2 - $y1, 2));
0 ignored issues
show
Unused Code introduced by
$length 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...
1884
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method DrawLine() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1885
1886
            /*
1 ignored issue
show
Unused Code Comprehensibility introduced by
44% 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...
1887
        $lean = ($y2 - $y1) / ($x2 - $x1);
1888
        $lean2 = -1 / $lean;
1889
        $sin = $lean / ($y2 - $y1);
1890
        $cos = $lean / ($x2 - $x1);
1891
1892
        $pts[] = $x1 + (-$weight * $sin); $pts[] = $y1 + (-$weight * $cos);
1893
        $pts[] = $x1 + (+$weight * $sin); $pts[] = $y1 + (+$weight * $cos);
1894
        $pts[] = $x2 + (+$weight * $sin); $pts[] = $y2 + (+$weight * $cos);
1895
        $pts[] = $x2 + (-$weight * $sin); $pts[] = $y2 + (-$weight * $cos);
1896
         */
1897
        }
1898
1899
        //print_r($pts);exit;
1 ignored issue
show
Unused Code Comprehensibility introduced by
86% 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...
1900
        if (count($pts) / 2 < 3) {
1901
            return;
1902
        }
1903
1904
        imagesetthickness($im, 1);
1905
        imagefilledpolygon($im, $pts, count($pts) / 2, $color);
1906
1907
        $weight *= 2;
1908
1909
        //        $this->DrawImageSmoothArc($im, $x1, $y1, $weight, $weight, 0, 360, $color);
1 ignored issue
show
Unused Code Comprehensibility introduced by
69% 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...
1910
        //        $this->DrawImageSmoothArc($im, $x2, $y2, $weight, $weight, 0, 360, $color);
1 ignored issue
show
Unused Code Comprehensibility introduced by
69% 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...
1911
    }
1912
1913
    public function DrawImageSmoothArc($im, $xc, $yc, $w, $h, $s, $e, $color, $style = null)
0 ignored issues
show
Unused Code introduced by
The parameter $style is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1914
    {
1915
        $tmp = $s;
1916
        $s   = (360 - $e) / 180 * M_PI;
1917
        $e   = (360 - $tmp) / 180 * M_PI;
1918
        return imageSmoothArc($im, round($xc), round($yc), round($w), round($h), $this->CreateColorForImageSmoothArc($color), $s, $e);
1919
    }
1920
1921
    public function CreateColorForImageSmoothArc($color)
1922
    {
1923
        $alpha = $color >> 24 & 0xFF;
1924
        $red   = $color >> 16 & 0xFF;
1925
        $green = $color >> 8 & 0xFF;
1926
        $blue  = $color & 0xFF;
1927
1928
        return [$red, $green, $blue, $alpha];
1929
    }
1930
1931
    public function imageSmoothCircle(&$img, $cx, $cy, $cr, $color)
1932
    {
1933
        $ir   = $cr;
1934
        $ix   = 0;
1935
        $iy   = $ir;
1936
        $ig   = 2 * $ir - 3;
1937
        $idgr = -6;
1938
        $idgd = 4 * $ir - 10;
1939
        $fill = imageColorExactAlpha($img, $color['R'], $color['G'], $color['B'], 0);
1940
        imageLine($img, $cx + $cr - 1, $cy, $cx, $cy, $fill);
1941
        imageLine($img, $cx - $cr + 1, $cy, $cx - 1, $cy, $fill);
1942
        imageLine($img, $cx, $cy + $cr - 1, $cx, $cy + 1, $fill);
1943
        imageLine($img, $cx, $cy - $cr + 1, $cx, $cy - 1, $fill);
1944
        $draw = imageColorExactAlpha($img, $color['R'], $color['G'], $color['B'], 42);
1945
        imageSetPixel($img, $cx + $cr, $cy, $draw);
1946
        imageSetPixel($img, $cx - $cr, $cy, $draw);
1947
        imageSetPixel($img, $cx, $cy + $cr, $draw);
1948
        imageSetPixel($img, $cx, $cy - $cr, $draw);
1949
        while ($ix <= $iy - 2) {
1950
            if ($ig < 0) {
1951
                $ig += $idgd;
1952
                $idgd -= 8;
1953
                $iy--;
1954
            } else {
1955
                $ig += $idgr;
1956
                $idgd -= 4;
1957
            }
1958
            $idgr -= 4;
1959
            $ix++;
1960
            imageLine($img, $cx + $ix, $cy + $iy - 1, $cx + $ix, $cy + $ix, $fill);
1961
            imageLine($img, $cx + $ix, $cy - $iy + 1, $cx + $ix, $cy - $ix, $fill);
1962
            imageLine($img, $cx - $ix, $cy + $iy - 1, $cx - $ix, $cy + $ix, $fill);
1963
            imageLine($img, $cx - $ix, $cy - $iy + 1, $cx - $ix, $cy - $ix, $fill);
1964
            imageLine($img, $cx + $iy - 1, $cy + $ix, $cx + $ix, $cy + $ix, $fill);
1965
            imageLine($img, $cx + $iy - 1, $cy - $ix, $cx + $ix, $cy - $ix, $fill);
1966
            imageLine($img, $cx - $iy + 1, $cy + $ix, $cx - $ix, $cy + $ix, $fill);
1967
            imageLine($img, $cx - $iy + 1, $cy - $ix, $cx - $ix, $cy - $ix, $fill);
1968
            $filled = 0;
1969
            for ($xx = $ix - 0.45; $xx < $ix + 0.5; $xx += 0.2) {
1970
                for ($yy = $iy - 0.45; $yy < $iy + 0.5; $yy += 0.2) {
1971
                    if (sqrt(pow($xx, 2) + pow($yy, 2)) < $cr) {
1972
                        $filled += 4;
1973
                    }
1974
                }
1975
            }
1976
            $draw = imageColorExactAlpha($img, $color['R'], $color['G'], $color['B'], (100 - $filled));
1977
            imageSetPixel($img, $cx + $ix, $cy + $iy, $draw);
1978
            imageSetPixel($img, $cx + $ix, $cy - $iy, $draw);
1979
            imageSetPixel($img, $cx - $ix, $cy + $iy, $draw);
1980
            imageSetPixel($img, $cx - $ix, $cy - $iy, $draw);
1981
            imageSetPixel($img, $cx + $iy, $cy + $ix, $draw);
1982
            imageSetPixel($img, $cx + $iy, $cy - $ix, $draw);
1983
            imageSetPixel($img, $cx - $iy, $cy + $ix, $draw);
1984
            imageSetPixel($img, $cx - $iy, $cy - $ix, $draw);
1985
        }
1986
    }
1987
1988 View Code Duplication
    public function __get($name)
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...
1989
    {
1990
        if (strpos($name, 'raw_') !== false) {
1991
            // if $name == 'raw_left_margin' , return $this->_left_margin;
1 ignored issue
show
Unused Code Comprehensibility introduced by
48% 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...
1992
            $variable_name = '_' . str_replace('raw_', '', $name);
1993
            return $this->$variable_name;
1994
        }
1995
1996
        $variable_name = '_' . $name;
1997
1998
        if (isset($this->$variable_name)) {
1999
            return $this->$variable_name * SUPERSAMPLING_SCALE;
2000
        } else {
2001
            Util\JpGraphError::RaiseL('25132', $name);
2002
        }
2003
    }
2004
2005
    public function __set($name, $value)
2006
    {
2007
        $this->{'_' . $name} = $value;
2008
    }
2009
} // CLASS
2010