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

GTextTableCell::StrokeHGrid()   D

Complexity

Conditions 16
Paths 46

Size

Total Lines 48
Code Lines 26

Duplication

Lines 28
Ratio 58.33 %

Importance

Changes 0
Metric Value
cc 16
eloc 26
nc 46
nop 6
dl 28
loc 48
rs 4.9765
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Amenadiel\JpGraph\Text;
3
4
/*=======================================================================
5
// File:        JPGRAPH_TABLE.PHP
6
// Description: Classes to create basic tables of data
7
// Created:     2006-01-25
8
// Ver:         $Id: jpgraph_table.php 1514 2009-07-07 11:15:58Z ljp $
9
//
10
// Copyright (c) Asial Corporation. All rights reserved.
11
//========================================================================
12
 */
13
14
// Style of grid lines in table
15
DEFINE('TGRID_SINGLE', 1);
16
DEFINE('TGRID_DOUBLE', 2);
17
DEFINE('TGRID_DOUBLE2', 3);
18
19
// Type of constrain for image constrain
20
DEFINE('TIMG_WIDTH', 1);
21
DEFINE('TIMG_HEIGHT', 2);
22
23
//---------------------------------------------------------------------
24
// CLASS GTextTableCell
25
// Description:
26
// Internal class that represents each cell in the table
27
//---------------------------------------------------------------------
28
class GTextTableCell
29
{
30
    public $iColSpan       = 1;
31
    public $iRowSpan       = 1;
32
    public $iMarginLeft    = 5;
33
    public $iMarginRight    = 5;
34
    public $iMarginTop    = 5;
35
    public $iMarginBottom    = 5;
36
    public $iVal           = null;
37
    private $iBGColor      = '';
38
    private $iFontColor      = 'black';
39
    private $iFF           = FF_FONT1;
40
    private $iFS           = FS_NORMAL;
41
    private $iFSize           = 10;
42
    private $iRow          = 0;
43
    private $iCol          = 0;
44
    private $iVertAlign    = 'bottom';
45
    private $iHorAlign    = 'left';
46
    private $iMerged       = false;
47
    private $iPRow       = null;
48
    private $iPCol       = null;
49
    private $iTable        = null;
50
    private $iGridColor    = array('darkgray', 'darkgray', 'darkgray', 'darkgray');
51
    private $iGridWeight   = array(1, 1, 0, 0); // left,top,bottom,right;
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...
52
    private $iGridStyle    = array(TGRID_SINGLE, TGRID_SINGLE, TGRID_SINGLE, TGRID_SINGLE); // left,top,bottom,right;
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...
53
    private $iNumberFormat = null;
54
    private $iIcon         = null;
55
    private $iIconConstrain         = array();
56
    private $iCSIMtarget   = '';
57
    private $iCSIMwintarget   = '';
58
    private $iCSIMalt   = '';
59
    private $iCSIMArea   = '';
60
61
    public function __construct($aVal = '', $aRow = 0, $aCol = 0)
62
    {
63
        $this->iVal           = new Text($aVal);
64
        $this->iRow           = $aRow;
65
        $this->iCol           = $aCol;
66
        $this->iPRow          = $aRow; // Initialiy each cell is its own parent
67
        $this->iPCol          = $aCol;
68
        $this->iIconConstrain = array(-1, -1);
69
    }
70
71
    public function Init($aTable)
72
    {
73
        $this->iTable = $aTable;
74
    }
75
76
    public function SetCSIMTarget($aTarget, $aAlt = '', $aWinTarget = '')
77
    {
78
        $this->iCSIMtarget    = $aTarget;
79
        $this->iCSIMwintarget = $aWinTarget;
80
        $this->iCSIMalt       = $aAlt;
81
    }
82
83
    public function GetCSIMArea()
84
    {
85
        if ($this->iCSIMtarget !== '') {
86
            return $this->iCSIMArea;
87
        } else {
88
            return '';
89
        }
90
    }
91
92
    public function SetImageConstrain($aType, $aVal)
93
    {
94
        if (!in_array($aType, array(TIMG_WIDTH, TIMG_HEIGHT))) {
95
            JpGraphError::RaiseL(27015);
96
        }
97
        $this->iIconConstrain = array($aType, $aVal);
98
    }
99
100
    public function SetCountryFlag($aFlag, $aScale = 1.0, $aMix = 100, $aStdSize = 3)
101
    {
102
        $this->iIcon = new IconPlot();
103
        $this->iIcon->SetCountryFlag($aFlag, 0, 0, $aScale, $aMix, $aStdSize);
104
    }
105
106
    public function SetImage($aFile, $aScale = 1.0, $aMix = 100)
107
    {
108
        $this->iIcon = new IconPlot($aFile, 0, 0, $aScale, $aMix);
109
    }
110
111
    public function SetImageFromString($aStr, $aScale = 1.0, $aMix = 100)
112
    {
113
        $this->iIcon = new IconPlot("", 0, 0, $aScale, $aMix);
114
        $this->iIcon->CreateFromString($aStr);
115
    }
116
117
    public function SetRowColSpan($aRowSpan, $aColSpan)
118
    {
119
        $this->iRowSpan = $aRowSpan;
120
        $this->iColSpan = $aColSpan;
121
        $this->iMerged  = true;
122
    }
123
124
    public function SetMerged($aPRow, $aPCol, $aFlg = true)
125
    {
126
        $this->iMerged = $aFlg;
127
        $this->iPRow   = $aPRow;
128
        $this->iPCol   = $aPCol;
129
    }
130
131
    public function IsMerged()
132
    {
133
        return $this->iMerged;
134
    }
135
136
    public function SetNumberFormat($aF)
137
    {
138
        $this->iNumberFormat = $aF;
139
    }
140
141
    public function Set($aTxt)
142
    {
143
        $this->iVal->Set($aTxt);
144
    }
145
146
    public function SetFont($aFF, $aFS, $aFSize)
147
    {
148
        $this->iFF    = $aFF;
149
        $this->iFS    = $aFS;
150
        $this->iFSize = $aFSize;
151
        $this->iVal->SetFont($aFF, $aFS, $aFSize);
152
    }
153
154
    public function SetFillColor($aColor)
155
    {
156
        $this->iBGColor = $aColor;
157
    }
158
159
    public function SetFontColor($aColor)
160
    {
161
        $this->iFontColor = $aColor;
162
    }
163
164 View Code Duplication
    public function SetGridColor($aLeft, $aTop = null, $aBottom = null, $aRight = null)
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...
165
    {
166
        if ($aLeft !== null) {
167
            $this->iGridColor[0] = $aLeft;
168
        }
169
170
        if ($aTop !== null) {
171
            $this->iGridColor[1] = $aTop;
172
        }
173
174
        if ($aBottom !== null) {
175
            $this->iGridColor[2] = $aBottom;
176
        }
177
178
        if ($aRight !== null) {
179
            $this->iGridColor[3] = $aRight;
180
        }
181
    }
182
183 View Code Duplication
    public function SetGridStyle($aLeft, $aTop = null, $aBottom = null, $aRight = null)
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...
184
    {
185
        if ($aLeft !== null) {
186
            $this->iGridStyle[0] = $aLeft;
187
        }
188
189
        if ($aTop !== null) {
190
            $this->iGridStyle[1] = $aTop;
191
        }
192
193
        if ($aBottom !== null) {
194
            $this->iGridStyle[2] = $aBottom;
195
        }
196
197
        if ($aRight !== null) {
198
            $this->iGridStyle[3] = $aRight;
199
        }
200
    }
201
202 View Code Duplication
    public function SetGridWeight($aLeft = null, $aTop = null, $aBottom = null, $aRight = null)
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...
203
    {
204
        if ($aLeft !== null) {
205
            $this->iGridWeight[0] = $aLeft;
206
        }
207
208
        if ($aTop !== null) {
209
            $this->iGridWeight[1] = $aTop;
210
        }
211
212
        if ($aBottom !== null) {
213
            $this->iGridWeight[2] = $aBottom;
214
        }
215
216
        if ($aRight !== null) {
217
            $this->iGridWeight[3] = $aRight;
218
        }
219
    }
220
221
    public function SetMargin($aLeft, $aRight, $aTop, $aBottom)
222
    {
223
        $this->iMarginLeft   = $aLeft;
224
        $this->iMarginRight  = $aRight;
225
        $this->iMarginTop    = $aTop;
226
        $this->iMarginBottom = $aBottom;
227
    }
228
229
    public function GetWidth($aImg)
230
    {
231 View Code Duplication
        if ($this->iIcon !== null) {
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...
232
            if ($this->iIconConstrain[0] == TIMG_WIDTH) {
233
                $this->iIcon->SetScale(1);
234
                $tmp = $this->iIcon->GetWidthHeight();
235
                $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[0]);
236
            } elseif ($this->iIconConstrain[0] == TIMG_HEIGHT) {
237
                $this->iIcon->SetScale(1);
238
                $tmp = $this->iIcon->GetWidthHeight();
239
                $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[1]);
240
            }
241
            $tmp    = $this->iIcon->GetWidthHeight();
242
            $iwidth = $tmp[0];
243
        } else {
244
            $iwidth = 0;
245
        }
246
        if ($this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 0) {
247
            $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetWidth($aImg);
248
        } elseif ($this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 90) {
249
            $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetFontHeight($aImg) + 2;
250 View Code Duplication
        } else {
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...
251
            $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetWidth($aImg) + 2;
252
        }
253
254
        $pcolspan = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iColSpan;
255
        return round(max($iwidth, $pwidth) / $pcolspan) + $this->iMarginLeft + $this->iMarginRight;
256
    }
257
258
    public function GetHeight($aImg)
259
    {
260 View Code Duplication
        if ($this->iIcon !== null) {
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...
261
            if ($this->iIconConstrain[0] == TIMG_WIDTH) {
262
                $this->iIcon->SetScale(1);
263
                $tmp = $this->iIcon->GetWidthHeight();
264
                $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[0]);
265
            } elseif ($this->iIconConstrain[0] == TIMG_HEIGHT) {
266
                $this->iIcon->SetScale(1);
267
                $tmp = $this->iIcon->GetWidthHeight();
268
                $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[1]);
269
            }
270
            $tmp     = $this->iIcon->GetWidthHeight();
271
            $iheight = $tmp[1];
272
        } else {
273
            $iheight = 0;
274
        }
275
        if ($this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 0) {
276
            $pheight = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetHeight($aImg);
277 View Code Duplication
        } else {
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...
278
            $pheight = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetHeight($aImg) + 1;
279
        }
280
        $prowspan = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iRowSpan;
281
        return round(max($iheight, $pheight) / $prowspan) + $this->iMarginTop + $this->iMarginBottom;
282
    }
283
284
    public function SetAlign($aHorAlign = 'left', $aVertAlign = 'bottom')
285
    {
286
        $aHorAlign  = strtolower($aHorAlign);
287
        $aVertAlign = strtolower($aVertAlign);
288
        $chk        = array('left', 'right', 'center', 'bottom', 'top', 'middle');
289
        if (!in_array($aHorAlign, $chk) || !in_array($aVertAlign, $chk)) {
290
            JpGraphError::RaiseL(27011, $aHorAlign, $aVertAlign);
291
        }
292
        $this->iVertAlign = $aVertAlign;
293
        $this->iHorAlign  = $aHorAlign;
294
    }
295
296
    public function AdjustMarginsForGrid()
297
    {
298 View Code Duplication
        if ($this->iCol > 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...
299
            switch ($this->iGridStyle[0]) {
300
                case TGRID_SINGLE:$wf = 1;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
301
                    break;
302
                case TGRID_DOUBLE:$wf = 3;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
303
                    break;
304
                case TGRID_DOUBLE2:$wf = 4;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
305
                    break;
306
            }
307
            $this->iMarginLeft += $this->iGridWeight[0] * $wf;
0 ignored issues
show
Bug introduced by
The variable $wf 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...
308
        }
309 View Code Duplication
        if ($this->iRow > 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...
310
            switch ($this->iGridStyle[1]) {
311
                case TGRID_SINGLE:$wf = 1;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
312
                    break;
313
                case TGRID_DOUBLE:$wf = 3;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
314
                    break;
315
                case TGRID_DOUBLE2:$wf = 4;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
316
                    break;
317
            }
318
            $this->iMarginTop += $this->iGridWeight[1] * $wf;
319
        }
320 View Code Duplication
        if ($this->iRow + $this->iRowSpan - 1 < $this->iTable->iSize[0] - 1) {
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...
321
            switch ($this->iGridStyle[2]) {
322
                case TGRID_SINGLE:$wf = 1;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
323
                    break;
324
                case TGRID_DOUBLE:$wf = 3;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
325
                    break;
326
                case TGRID_DOUBLE2:$wf = 4;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
327
                    break;
328
            }
329
            $this->iMarginBottom += $this->iGridWeight[2] * $wf;
330
        }
331 View Code Duplication
        if ($this->iCol + $this->iColSpan - 1 < $this->iTable->iSize[1] - 1) {
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...
332
            switch ($this->iGridStyle[3]) {
333
                case TGRID_SINGLE:$wf = 1;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
334
                    break;
335
                case TGRID_DOUBLE:$wf = 3;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
336
                    break;
337
                case TGRID_DOUBLE2:$wf = 4;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
338
                    break;
339
            }
340
            $this->iMarginRight += $this->iGridWeight[3] * $wf;
341
        }
342
    }
343
344
    public function StrokeVGrid($aImg, $aX, $aY, $aWidth, $aHeight, $aDir = 1)
345
    {
346
        // Left or right grid line
347
        // For the right we increase the X-pos and for the right we decrease it. This is
348
        // determined by the direction argument.
349
        $idx = $aDir == 1 ? 0 : 3;
350
351
        // We don't stroke the grid lines that are on the edge of the table since this is
352
        // the place of the border.
353
        if ((($this->iCol > 0 && $idx == 0) || ($this->iCol + $this->iColSpan - 1 < $this->iTable->iSize[1] - 1 && $idx == 3))
354
            && $this->iGridWeight[$idx] > 0) {
355
            $x = $aDir == 1 ? $aX : $aX + $aWidth - 1;
356
            $y = $aY + $aHeight - 1;
357
            $aImg->SetColor($this->iGridColor[$idx]);
358
            switch ($this->iGridStyle[$idx]) {
359 View Code Duplication
                case TGRID_SINGLE:
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...
360
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
361
                        $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y);
362
                    }
363
364
                    break;
365
366 View Code Duplication
                case TGRID_DOUBLE:
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...
367
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
368
                        $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y);
369
                    }
370
371
                    $x += $this->iGridWeight[$idx] * 2;
372
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
373
                        $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y);
374
                    }
375
376
                    break;
377
378 View Code Duplication
                case TGRID_DOUBLE2:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
379
                    for ($i = 0; $i < $this->iGridWeight[$idx] * 2; ++$i) {
380
                        $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y);
381
                    }
382
383
                    $x += $this->iGridWeight[$idx] * 3;
384
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
385
                        $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y);
386
                    }
387
388
                    break;
389
            }
390
        }
391
    }
392
393
    public function StrokeHGrid($aImg, $aX, $aY, $aWidth, $aHeight, $aDir = 1)
394
    {
395
        // Top or bottom grid line
396
        // For the left we increase the X-pos and for the right we decrease it. This is
397
        // determined by the direction argument.
398
        $idx = $aDir == 1 ? 1 : 2;
399
400
        // We don't stroke the grid lines that are on the edge of the table since this is
401
        // the place of the border.
402
        if ((($this->iRow > 0 && $idx == 1) || ($this->iRow + $this->iRowSpan - 1 < $this->iTable->iSize[0] - 1 && $idx == 2))
403
            && $this->iGridWeight[$idx] > 0) {
404
            $y = $aDir == 1 ? $aY : $aY + $aHeight - 1;
405
            $x = $aX + $aWidth - 1;
406
            $aImg->SetColor($this->iGridColor[$idx]);
407
            switch ($this->iGridStyle[$idx]) {
408 View Code Duplication
                case TGRID_SINGLE:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
409
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
410
                        $aImg->Line($aX, $y + $i, $x, $y + $i);
411
                    }
412
413
                    break;
414
415 View Code Duplication
                case TGRID_DOUBLE:
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...
416
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
417
                        $aImg->Line($aX, $y + $i, $x, $y + $i);
418
                    }
419
420
                    $y += $this->iGridWeight[$idx] * 2;
421
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
422
                        $aImg->Line($aX, $y + $i, $x, $y + $i);
423
                    }
424
425
                    break;
426
427 View Code Duplication
                case TGRID_DOUBLE2:
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...
428
                    for ($i = 0; $i < $this->iGridWeight[$idx] * 2; ++$i) {
429
                        $aImg->Line($aX, $y + $i, $x, $y + $i);
430
                    }
431
432
                    $y += $this->iGridWeight[$idx] * 3;
433
                    for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) {
434
                        $aImg->Line($aX, $y + $i, $x, $y + $i);
435
                    }
436
437
                    break;
438
            }
439
        }
440
    }
441
442
    public function Stroke($aImg, $aX, $aY, $aWidth, $aHeight)
443
    {
444
        // If this is a merged cell we only stroke if it is the parent cell.
445
        // The parent cell holds the merged cell block
446
        if ($this->iMerged && ($this->iRow != $this->iPRow || $this->iCol != $this->iPCol)) {
447
            return;
448
        }
449
450
        if ($this->iBGColor != '') {
451
            $aImg->SetColor($this->iBGColor);
452
            $aImg->FilledRectangle($aX, $aY, $aX + $aWidth - 1, $aY + $aHeight - 1);
453
        }
454
455
        $coords = $aX . ',' . $aY . ',' . ($aX + $aWidth - 1) . ',' . $aY . ',' . ($aX + $aWidth - 1) . ',' . ($aY + $aHeight - 1) . ',' . $aX . ',' . ($aY + $aHeight - 1);
456
        if (!empty($this->iCSIMtarget)) {
457
            $this->iCSIMArea = '<area shape="poly" coords="' . $coords . '" href="' . $this->iCSIMtarget . '"';
458
            if (!empty($this->iCSIMwintarget)) {
459
                $this->iCSIMArea .= " target=\"" . $this->iCSIMwintarget . "\"";
460
            }
461
            if (!empty($this->iCSIMalt)) {
462
                $this->iCSIMArea .= ' alt="' . $this->iCSIMalt . '" title="' . $this->iCSIMalt . "\" ";
463
            }
464
            $this->iCSIMArea .= " />\n";
465
        }
466
467
        $this->StrokeVGrid($aImg, $aX, $aY, $aWidth, $aHeight);
468
        $this->StrokeVGrid($aImg, $aX, $aY, $aWidth, $aHeight, -1);
469
        $this->StrokeHGrid($aImg, $aX, $aY, $aWidth, $aHeight);
470
        $this->StrokeHGrid($aImg, $aX, $aY, $aWidth, $aHeight, -1);
471
472
        if ($this->iIcon !== null) {
473 View Code Duplication
            switch ($this->iHorAlign) {
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...
474
                case 'left':
475
                    $x       = $aX + $this->iMarginLeft;
476
                    $hanchor = 'left';
477
                    break;
478
                case 'center':
479
                case 'middle':
480
                    $x       = $aX + $this->iMarginLeft + round(($aWidth - $this->iMarginLeft - $this->iMarginRight) / 2);
481
                    $hanchor = 'center';
482
                    break;
483
                case 'right':
484
                    $x       = $aX + $aWidth - $this->iMarginRight - 1;
485
                    $hanchor = 'right';
486
                    break;
487
                default:
488
                    JpGraphError::RaiseL(27012, $this->iHorAlign);
489
            }
490
491 View Code Duplication
            switch ($this->iVertAlign) {
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...
492
                case 'top':
493
                    $y       = $aY + $this->iMarginTop;
494
                    $vanchor = 'top';
495
                    break;
496
                case 'center':
497
                case 'middle':
498
                    $y       = $aY + $this->iMarginTop + round(($aHeight - $this->iMarginTop - $this->iMarginBottom) / 2);
499
                    $vanchor = 'center';
500
                    break;
501
                case 'bottom':
502
                    $y       = $aY + $aHeight - 1 - $this->iMarginBottom;
503
                    $vanchor = 'bottom';
504
                    break;
505
                default:
506
                    JpGraphError::RaiseL(27012, $this->iVertAlign);
507
            }
508
            $this->iIcon->SetAnchor($hanchor, $vanchor);
0 ignored issues
show
Bug introduced by
The variable $hanchor 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 $vanchor 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...
509
            $this->iIcon->_Stroke($aImg, $x, $y);
0 ignored issues
show
Bug introduced by
The variable $x 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 $y 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...
510
        }
511
        $this->iVal->SetColor($this->iFontColor);
512
        $this->iVal->SetFont($this->iFF, $this->iFS, $this->iFSize);
513
        switch ($this->iHorAlign) {
514
            case 'left':
515
                $x = $aX + $this->iMarginLeft;
516
                break;
517
            case 'center':
518
            case 'middle':
519
                $x = $aX + $this->iMarginLeft + round(($aWidth - $this->iMarginLeft - $this->iMarginRight) / 2);
520
                break;
521
            case 'right':
522
                $x = $aX + $aWidth - $this->iMarginRight - 1;
523
                break;
524
            default:
525
                JpGraphError::RaiseL(27012, $this->iHorAlign);
526
        }
527
        // A workaround for the shortcomings in the TTF font handling in GD
528
        // The anchor position for rotated text (=90) is to "short" so we add
529
        // an offset based on the actual font size
530
        if ($this->iVal->dir != 0 && $this->iVal->font_family >= 10) {
531
            $aY += 4 + round($this->iVal->font_size * 0.8);
0 ignored issues
show
Bug introduced by
The property font_size does not seem to exist. Did you mean _font_size?

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...
532
        }
533
        switch ($this->iVertAlign) {
534
            case 'top':
535
                $y = $aY + $this->iMarginTop;
536
                break;
537
            case 'center':
538
            case 'middle':
539
                $y = $aY + $this->iMarginTop + round(($aHeight - $this->iMarginTop - $this->iMarginBottom) / 2);
540
                //$y -= round($this->iVal->GetFontHeight($aImg)/2);
1 ignored issue
show
Unused Code Comprehensibility introduced by
62% 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...
541
                $y -= round($this->iVal->GetHeight($aImg) / 2);
542
                break;
543
            case 'bottom':
544
                //$y = $aY+$aHeight-1-$this->iMarginBottom-$this->iVal->GetFontHeight($aImg);
1 ignored issue
show
Unused Code Comprehensibility introduced by
57% 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...
545
                $y = $aY + $aHeight - $this->iMarginBottom - $this->iVal->GetHeight($aImg);
546
                break;
547
            default:
548
                JpGraphError::RaiseL(27012, $this->iVertAlign);
549
        }
550
        $this->iVal->SetAlign($this->iHorAlign, 'top');
551
        if ($this->iNumberFormat !== null && is_numeric($this->iVal->t)) {
552
            $this->iVal->t = sprintf($this->iNumberFormat, $this->iVal->t);
553
        }
554
        $this->iVal->Stroke($aImg, $x, $y);
555
    }
556
}
557
558
/*
559
EOF
560
 */
561