Conditions | 31 |
Paths | 103 |
Total Lines | 180 |
Code Lines | 150 |
Lines | 28 |
Ratio | 15.56 % |
Changes | 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 |
||
192 | public function StrokeAngleLabels($pos, $type) |
||
193 | { |
||
194 | if (!$this->show_angle_label) { |
||
195 | return; |
||
196 | } |
||
197 | |||
198 | $x0 = round($this->img->left_margin + $this->img->plotwidth / 2) + 1; |
||
199 | |||
200 | $d = max($this->img->plotwidth, $this->img->plotheight) * 1.42; |
||
201 | $a = $this->angle_step; |
||
202 | $t = new Text(); |
||
203 | $t->SetColor($this->angle_fontcolor); |
||
204 | $t->SetFont($this->angle_fontfam, $this->angle_fontstyle, $this->angle_fontsize); |
||
205 | $xright = $this->img->width - $this->img->right_margin; |
||
206 | $ytop = $this->img->top_margin; |
||
207 | $xleft = $this->img->left_margin; |
||
208 | $ybottom = $this->img->height - $this->img->bottom_margin; |
||
209 | $ha = 'left'; |
||
210 | $va = 'center'; |
||
211 | $w = $this->img->plotwidth / 2; |
||
212 | $h = $this->img->plotheight / 2; |
||
213 | $xt = $x0; |
||
214 | $yt = $pos; |
||
215 | $margin = 5; |
||
216 | |||
217 | $tl = $this->angle_tick_len; // Outer len |
||
218 | $tl2 = $this->angle_tick_len2; // Interior len |
||
219 | |||
220 | $this->img->SetColor($this->angle_tick_color); |
||
221 | $rot90 = $this->img->a == 90; |
||
222 | |||
223 | if ($type == POLAR_360) { |
||
224 | |||
225 | // Corner angles of the four corners |
||
226 | $ca1 = atan($h / $w) / M_PI * 180; |
||
227 | $ca2 = 180 - $ca1; |
||
228 | $ca3 = $ca1 + 180; |
||
229 | $ca4 = 360 - $ca1; |
||
230 | $end = 360; |
||
231 | |||
232 | while ($a < $end) { |
||
233 | $ca = cos($a / 180 * M_PI); |
||
234 | $sa = sin($a / 180 * M_PI); |
||
235 | $x = $d * $ca; |
||
236 | $y = $d * $sa; |
||
237 | $xt = 1000; |
||
238 | $yt = 1000; |
||
239 | if ($a <= $ca1 || $a >= $ca4) { |
||
240 | $yt = $pos - $w * $y / $x; |
||
241 | $xt = $xright + $margin; |
||
242 | if ($rot90) { |
||
243 | $ha = 'center'; |
||
244 | $va = 'top'; |
||
245 | } else { |
||
246 | $ha = 'left'; |
||
247 | $va = 'center'; |
||
248 | } |
||
249 | $x1 = $xright - $tl2; |
||
250 | $x2 = $xright + $tl; |
||
251 | $y1 = $y2 = $yt; |
||
252 | View Code Duplication | } elseif ($a > $ca1 && $a < $ca2) { |
|
253 | $xt = $x0 + $h * $x / $y; |
||
254 | $yt = $ytop - $margin; |
||
255 | if ($rot90) { |
||
256 | $ha = 'left'; |
||
257 | $va = 'center'; |
||
258 | } else { |
||
259 | $ha = 'center'; |
||
260 | $va = 'bottom'; |
||
261 | } |
||
262 | $y1 = $ytop + $tl2; |
||
263 | $y2 = $ytop - $tl; |
||
264 | $x1 = $x2 = $xt; |
||
265 | } elseif ($a >= $ca2 && $a <= $ca3) { |
||
266 | $yt = $pos + $w * $y / $x; |
||
267 | $xt = $xleft - $margin; |
||
268 | if ($rot90) { |
||
269 | $ha = 'center'; |
||
270 | $va = 'bottom'; |
||
271 | } else { |
||
272 | $ha = 'right'; |
||
273 | $va = 'center'; |
||
274 | } |
||
275 | $x1 = $xleft + $tl2; |
||
276 | $x2 = $xleft - $tl; |
||
277 | $y1 = $y2 = $yt; |
||
278 | } else { |
||
279 | $xt = $x0 - $h * $x / $y; |
||
280 | $yt = $ybottom + $margin; |
||
281 | if ($rot90) { |
||
282 | $ha = 'right'; |
||
283 | $va = 'center'; |
||
284 | } else { |
||
285 | $ha = 'center'; |
||
286 | $va = 'top'; |
||
287 | } |
||
288 | $y1 = $ybottom - $tl2; |
||
289 | $y2 = $ybottom + $tl; |
||
290 | $x1 = $x2 = $xt; |
||
291 | } |
||
292 | if ($a != 0 && $a != 180) { |
||
293 | $t->Align($ha, $va); |
||
294 | if ($this->scale->clockwise) { |
||
295 | $t->Set(360 - $a); |
||
296 | } else { |
||
297 | $t->Set($a); |
||
298 | } |
||
299 | if ($this->show_angle_mark && $t->font_family > 4) { |
||
300 | $a .= SymChar::Get('degree'); |
||
301 | } |
||
302 | $t->Stroke($this->img, $xt, $yt); |
||
303 | if ($this->show_angle_tick) { |
||
304 | $this->img->Line($x1, $y1, $x2, $y2); |
||
305 | } |
||
306 | } |
||
307 | $a += $this->angle_step; |
||
308 | } |
||
309 | } else { |
||
310 | // POLAR_HALF |
||
311 | $ca1 = atan($h / $w * 2) / M_PI * 180; |
||
312 | $ca2 = 180 - $ca1; |
||
313 | $end = 180; |
||
314 | while ($a < $end) { |
||
315 | $ca = cos($a / 180 * M_PI); |
||
316 | $sa = sin($a / 180 * M_PI); |
||
317 | $x = $d * $ca; |
||
318 | $y = $d * $sa; |
||
319 | if ($a <= $ca1) { |
||
320 | $yt = $pos - $w * $y / $x; |
||
321 | $xt = $xright + $margin; |
||
322 | if ($rot90) { |
||
323 | $ha = 'center'; |
||
324 | $va = 'top'; |
||
325 | } else { |
||
326 | $ha = 'left'; |
||
327 | $va = 'center'; |
||
328 | } |
||
329 | $x1 = $xright - $tl2; |
||
330 | $x2 = $xright + $tl; |
||
331 | $y1 = $y2 = $yt; |
||
332 | View Code Duplication | } elseif ($a > $ca1 && $a < $ca2) { |
|
333 | $xt = $x0 + 2 * $h * $x / $y; |
||
334 | $yt = $ytop - $margin; |
||
335 | if ($rot90) { |
||
336 | $ha = 'left'; |
||
337 | $va = 'center'; |
||
338 | } else { |
||
339 | $ha = 'center'; |
||
340 | $va = 'bottom'; |
||
341 | } |
||
342 | $y1 = $ytop + $tl2; |
||
343 | $y2 = $ytop - $tl; |
||
344 | $x1 = $x2 = $xt; |
||
345 | } elseif ($a >= $ca2) { |
||
346 | $yt = $pos + $w * $y / $x; |
||
347 | $xt = $xleft - $margin; |
||
348 | if ($rot90) { |
||
349 | $ha = 'center'; |
||
350 | $va = 'bottom'; |
||
351 | } else { |
||
352 | $ha = 'right'; |
||
353 | $va = 'center'; |
||
354 | } |
||
355 | $x1 = $xleft + $tl2; |
||
356 | $x2 = $xleft - $tl; |
||
357 | $y1 = $y2 = $yt; |
||
358 | } |
||
359 | $t->Align($ha, $va); |
||
360 | if ($this->show_angle_mark && $t->font_family > 4) { |
||
361 | $a .= SymChar::Get('degree'); |
||
362 | } |
||
363 | $t->Set($a); |
||
364 | $t->Stroke($this->img, $xt, $yt); |
||
365 | if ($this->show_angle_tick) { |
||
366 | $this->img->Line($x1, $y1, $x2, $y2); |
||
367 | } |
||
368 | $a += $this->angle_step; |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | |||
462 |
This check marks private properties in classes that are never used. Those properties can be removed.