| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 144 |
| Code Lines | 73 |
| 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 |
||
| 194 | public function Stroke($aStrokeFileName = '') |
||
| 195 | { |
||
| 196 | // If the filename is the predefined value = '_csim_special_' |
||
| 197 | // we assume that the call to stroke only needs to do enough |
||
| 198 | // to correctly generate the CSIM maps. |
||
| 199 | // We use this variable to skip things we don't strictly need |
||
| 200 | // to do to generate the image map to improve performance |
||
| 201 | // a best we can. Therefor you will see a lot of tests !$_csim in the |
||
| 202 | // code below. |
||
| 203 | $_csim = ($aStrokeFileName === _CSIM_SPECIALFILE); |
||
| 204 | |||
| 205 | // We need to know if we have stroked the plot in the |
||
| 206 | // GetCSIMareas. Otherwise the CSIM hasn't been generated |
||
| 207 | // and in the case of GetCSIM called before stroke to generate |
||
| 208 | // CSIM without storing an image to disk GetCSIM must call Stroke. |
||
| 209 | $this->iHasStroked = true; |
||
| 210 | |||
| 211 | $n = safe_count($this->plots); |
||
| 212 | // Set Y-scale |
||
| 213 | |||
| 214 | if (!$this->yscale->IsSpecified() && safe_count($this->plots) > 0) { |
||
| 215 | list($min, $max) = $this->GetPlotsYMinMax($this->plots); |
||
| 216 | $this->yscale->AutoScale($this->img, 0, $max, $this->len / $this->ytick_factor); |
||
| 217 | } elseif ($this->yscale->IsSpecified() && |
||
| 218 | ($this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified())) { |
||
| 219 | // The tick calculation will use the user suplied min/max values to determine |
||
| 220 | // the ticks. If auto_ticks is false the exact user specifed min and max |
||
| 221 | // values will be used for the scale. |
||
| 222 | // If auto_ticks is true then the scale might be slightly adjusted |
||
| 223 | // so that the min and max values falls on an even major step. |
||
| 224 | $min = $this->yscale->scale[0]; |
||
| 225 | $max = $this->yscale->scale[1]; |
||
| 226 | $this->yscale->AutoScale( |
||
| 227 | $this->img, |
||
| 228 | $min, |
||
| 229 | $max, |
||
| 230 | $this->len / $this->ytick_factor, |
||
| 231 | $this->yscale->auto_ticks |
||
| 232 | ); |
||
| 233 | } |
||
| 234 | |||
| 235 | // Set start position end length of scale (in absolute pixels) |
||
| 236 | $this->yscale->SetConstants($this->posx, $this->len); |
||
| 237 | |||
| 238 | // We need as many axis as there are data points |
||
| 239 | $nbrpnts = $this->plots[0]->GetCount(); |
||
| 240 | |||
| 241 | // If we have no titles just number the axis 1,2,3,... |
||
| 242 | if ($this->axis_title == null) { |
||
| 243 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 244 | $this->axis_title[$i] = $i + 1; |
||
| 245 | } |
||
| 246 | } elseif (safe_count($this->axis_title) < $nbrpnts) { |
||
| 247 | Util\JpGraphError::RaiseL(18007); |
||
| 248 | // ("Number of titles does not match number of points in plot."); |
||
| 249 | } |
||
| 250 | for ($i = 0; $i < $n; ++$i) { |
||
| 251 | if ($nbrpnts != $this->plots[$i]->GetCount()) { |
||
| 252 | Util\JpGraphError::RaiseL(18008); |
||
| 253 | //("Each radar plot must have the same number of data points."); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | if (!$_csim) { |
||
| 258 | if ($this->background_image != '') { |
||
| 259 | $this->StrokeFrameBackground(); |
||
| 260 | } else { |
||
| 261 | $this->StrokeFrame(); |
||
| 262 | $this->StrokeBackgroundGrad(); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | $astep = 2 * M_PI / $nbrpnts; |
||
| 266 | |||
| 267 | if (!$_csim) { |
||
| 268 | if ($this->iIconDepth == DEPTH_BACK) { |
||
| 269 | $this->StrokeIcons(); |
||
| 270 | } |
||
| 271 | |||
| 272 | // Prepare legends |
||
| 273 | for ($i = 0; $i < $n; ++$i) { |
||
| 274 | $this->plots[$i]->Legend($this); |
||
| 275 | } |
||
| 276 | $this->legend->Stroke($this->img); |
||
| 277 | $this->footer->Stroke($this->img); |
||
| 278 | } |
||
| 279 | |||
| 280 | if (!$_csim) { |
||
| 281 | if ($this->grid_depth == DEPTH_BACK) { |
||
| 282 | // Draw axis and grid |
||
| 283 | for ($i = 0, $a = M_PI / 2; $i < $nbrpnts; ++$i, $a += $astep) { |
||
| 284 | $this->axis->Stroke($this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0); |
||
|
|
|||
| 285 | } |
||
| 286 | $this->grid->Stroke($this->img, $grid); |
||
| 287 | } |
||
| 288 | if ($this->iIconDepth == DEPTH_BACK) { |
||
| 289 | $this->StrokeIcons(); |
||
| 290 | } |
||
| 291 | } |
||
| 292 | |||
| 293 | // Plot points |
||
| 294 | $a = M_PI / 2; |
||
| 295 | for ($i = 0; $i < $n; ++$i) { |
||
| 296 | $this->plots[$i]->Stroke($this->img, $this->posy, $this->yscale, $a); |
||
| 297 | } |
||
| 298 | |||
| 299 | if (!$_csim) { |
||
| 300 | if ($this->grid_depth != DEPTH_BACK) { |
||
| 301 | // Draw axis and grid |
||
| 302 | for ($i = 0, $a = M_PI / 2; $i < $nbrpnts; ++$i, $a += $astep) { |
||
| 303 | $this->axis->Stroke($this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0); |
||
| 304 | } |
||
| 305 | $this->grid->Stroke($this->img, $grid); |
||
| 306 | } |
||
| 307 | |||
| 308 | $this->StrokeTitles(); |
||
| 309 | $this->StrokeTexts(); |
||
| 310 | if ($this->iIconDepth == DEPTH_FRONT) { |
||
| 311 | $this->StrokeIcons(); |
||
| 312 | } |
||
| 313 | } |
||
| 314 | |||
| 315 | // Should we do any final image transformation |
||
| 316 | if ($this->iImgTrans && !$_csim) { |
||
| 317 | $tform = new Image\ImgTrans($this->img->img); |
||
| 318 | $this->img->img = $tform->Skew3D( |
||
| 319 | $this->iImgTransHorizon, |
||
| 320 | $this->iImgTransSkewDist, |
||
| 321 | $this->iImgTransDirection, |
||
| 322 | $this->iImgTransHighQ, |
||
| 323 | $this->iImgTransMinSize, |
||
| 324 | $this->iImgTransFillColor, |
||
| 325 | $this->iImgTransBorder |
||
| 326 | ); |
||
| 327 | } |
||
| 328 | |||
| 329 | if (!$_csim) { |
||
| 330 | // If the filename is given as the special "__handle" |
||
| 331 | // then the image handler is returned and the image is NOT |
||
| 332 | // streamed back |
||
| 333 | if ($aStrokeFileName == _IMG_HANDLER) { |
||
| 334 | return $this->img->img; |
||
| 335 | } |
||
| 336 | // Finally stream the generated picture |
||
| 337 | $this->cache->PutAndStream($this->img, $this->cache_name, $this->inline, $aStrokeFileName); |
||
| 338 | } |
||
| 341 |