| Conditions | 20 |
| Paths | 14 |
| Total Lines | 98 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 96 | public function DoStroke($aTicksPos, $aType, $aColor, $aWeight) |
||
| 97 | { |
||
| 98 | $nbrgrids = safe_count($aTicksPos); |
||
| 99 | if (!$this->show || $nbrgrids === 0) { |
||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($this->scale->type == 'y') { |
||
| 104 | $xl = $this->img->left_margin; |
||
| 105 | $xr = $this->img->width - $this->img->right_margin; |
||
| 106 | |||
| 107 | if ($this->fill) { |
||
| 108 | // Draw filled areas |
||
| 109 | $y2 = $aTicksPos[0]; |
||
| 110 | $i = 1; |
||
| 111 | while ($i < $nbrgrids) { |
||
| 112 | $y1 = $y2; |
||
| 113 | $y2 = $aTicksPos[$i++]; |
||
| 114 | $this->img->SetColor($this->fillcolor[$i & 1]); |
||
| 115 | $this->img->FilledRectangle($xl, $y1, $xr, $y2); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | $this->img->SetColor($aColor); |
||
| 120 | $this->img->SetLineWeight($aWeight); |
||
| 121 | |||
| 122 | // Draw grid lines |
||
| 123 | switch ($aType) { |
||
| 124 | case 'solid': |
||
| 125 | $style = LINESTYLE_SOLID; |
||
| 126 | |||
| 127 | break; |
||
| 128 | case 'dotted': |
||
| 129 | $style = LINESTYLE_DOTTED; |
||
| 130 | |||
| 131 | break; |
||
| 132 | case 'dashed': |
||
| 133 | $style = LINESTYLE_DASHED; |
||
| 134 | |||
| 135 | break; |
||
| 136 | case 'longdashed': |
||
| 137 | $style = LINESTYLE_LONGDASH; |
||
| 138 | |||
| 139 | break; |
||
| 140 | default: |
||
| 141 | $style = LINESTYLE_SOLID; |
||
| 142 | |||
| 143 | break; |
||
| 144 | } |
||
| 145 | |||
| 146 | for ($i = 0; $i < $nbrgrids; ++$i) { |
||
| 147 | $y = $aTicksPos[$i]; |
||
| 148 | $this->img->StyleLine($xl, $y, $xr, $y, $style, true); |
||
| 149 | } |
||
| 150 | } elseif ($this->scale->type == 'x') { |
||
| 151 | $yu = $this->img->top_margin; |
||
| 152 | $yl = $this->img->height - $this->img->bottom_margin; |
||
| 153 | $limit = $this->img->width - $this->img->right_margin; |
||
| 154 | |||
| 155 | if ($this->fill) { |
||
| 156 | // Draw filled areas |
||
| 157 | $x2 = $aTicksPos[0]; |
||
| 158 | $i = 1; |
||
| 159 | while ($i < $nbrgrids) { |
||
| 160 | $x1 = $x2; |
||
| 161 | $x2 = min($aTicksPos[$i++], $limit); |
||
| 162 | $this->img->SetColor($this->fillcolor[$i & 1]); |
||
| 163 | $this->img->FilledRectangle($x1, $yu, $x2, $yl); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | $this->img->SetColor($aColor); |
||
| 168 | $this->img->SetLineWeight($aWeight); |
||
| 169 | |||
| 170 | // We must also test for limit since we might have |
||
| 171 | // an offset and the number of ticks is calculated with |
||
| 172 | // assumption offset==0 so we might end up drawing one |
||
| 173 | // to many gridlines |
||
| 174 | $i = 0; |
||
| 175 | $x = $aTicksPos[$i]; |
||
|
|
|||
| 176 | while ($i < safe_count($aTicksPos) && ($x = $aTicksPos[$i]) <= $limit) { |
||
| 177 | if ($aType == 'solid') { |
||
| 178 | $this->img->Line($x, $yl, $x, $yu); |
||
| 179 | } elseif ($aType == 'dotted') { |
||
| 180 | $this->img->DashedLineForGrid($x, $yl, $x, $yu, 1, 6); |
||
| 181 | } elseif ($aType == 'dashed') { |
||
| 182 | $this->img->DashedLineForGrid($x, $yl, $x, $yu, 2, 4); |
||
| 183 | } elseif ($aType == 'longdashed') { |
||
| 184 | $this->img->DashedLineForGrid($x, $yl, $x, $yu, 8, 6); |
||
| 185 | } |
||
| 186 | |||
| 187 | ++$i; |
||
| 188 | } |
||
| 189 | } else { |
||
| 190 | Util\JpGraphError::RaiseL(25054, $this->scale->type); //('Internal error: Unknown grid axis ['.$this->scale->type.']'); |
||
| 191 | } |
||
| 192 | |||
| 193 | return true; |
||
| 194 | } |
||
| 196 |