Conditions | 24 |
Paths | 589 |
Total Lines | 102 |
Code Lines | 69 |
Lines | 27 |
Ratio | 26.47 % |
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 |
||
22 | public function Stroke($aOtherAxisScale, $aStrokeLabels = true) |
||
23 | { |
||
24 | if ($this->hide) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | if (is_numeric($this->pos)) { |
||
29 | $pos = $aOtherAxisScale->Translate($this->pos); |
||
30 | } else { |
||
31 | // Default to minimum of other scale if pos not set |
||
32 | if (($aOtherAxisScale->GetMinVal() >= 0 && $this->pos == false) || $this->pos == 'min') { |
||
33 | $pos = $aOtherAxisScale->scale_abs[0]; |
||
34 | } elseif ($this->pos == "max") { |
||
35 | $pos = $aOtherAxisScale->scale_abs[1]; |
||
36 | } else { |
||
37 | // If negative set x-axis at 0 |
||
38 | $this->pos = 0; |
||
39 | $pos = $aOtherAxisScale->Translate(0); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | $pos += $this->iDeltaAbsPos; |
||
44 | $this->img->SetLineWeight($this->weight); |
||
45 | $this->img->SetColor($this->color); |
||
46 | $this->img->SetFont($this->font_family, $this->font_style, $this->font_size); |
||
47 | |||
48 | if ($this->scale->type == "x") { |
||
49 | View Code Duplication | if (!$this->hide_line) { |
|
50 | // Stroke X-axis |
||
51 | $this->img->FilledRectangle( |
||
52 | $this->img->left_margin, |
||
53 | $pos, |
||
54 | $this->img->width - $this->img->right_margin, |
||
55 | $pos + $this->weight - 1 |
||
56 | ); |
||
57 | } |
||
58 | if ($this->title_side == SIDE_DOWN) { |
||
59 | $y = $pos + $this->img->GetFontHeight() + $this->title_margin + $this->title->margin; |
||
60 | $yalign = 'top'; |
||
61 | } else { |
||
62 | $y = $pos - $this->img->GetFontHeight() - $this->title_margin - $this->title->margin; |
||
63 | $yalign = 'bottom'; |
||
64 | } |
||
65 | |||
66 | View Code Duplication | if ($this->title_adjust == 'high') { |
|
67 | $this->title->SetPos($this->img->width - $this->img->right_margin, $y, 'right', $yalign); |
||
68 | } elseif ($this->title_adjust == 'middle' || $this->title_adjust == 'center') { |
||
69 | $this->title->SetPos(($this->img->width - $this->img->left_margin - $this->img->right_margin) / 2 + $this->img->left_margin, $y, 'center', $yalign); |
||
70 | } elseif ($this->title_adjust == 'low') { |
||
71 | $this->title->SetPos($this->img->left_margin, $y, 'left', $yalign); |
||
72 | } else { |
||
73 | Util\JpGraphError::RaiseL(25060, $this->title_adjust); //('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')'); |
||
1 ignored issue
–
show
|
|||
74 | } |
||
75 | } elseif ($this->scale->type == "y") { |
||
76 | // Add line weight to the height of the axis since |
||
77 | // the x-axis could have a width>1 and we want the axis to fit nicely together. |
||
78 | if (!$this->hide_line) { |
||
79 | // Stroke Y-axis |
||
80 | $this->img->FilledRectangle( |
||
81 | $pos - $this->weight + 1, |
||
82 | $this->img->top_margin, |
||
83 | $pos, |
||
84 | $this->img->height - $this->img->bottom_margin + $this->weight - 1 |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | $x = $pos; |
||
89 | if ($this->title_side == SIDE_LEFT) { |
||
90 | $x -= $this->title_margin; |
||
91 | $x -= $this->title->margin; |
||
92 | $halign = 'right'; |
||
93 | } else { |
||
94 | $x += $this->title_margin; |
||
95 | $x += $this->title->margin; |
||
96 | $halign = 'left'; |
||
97 | } |
||
98 | // If the user has manually specified an hor. align |
||
99 | // then we override the automatic settings with this |
||
100 | // specifed setting. Since default is 'left' we compare |
||
101 | // with that. (This means a manually set 'left' align |
||
102 | // will have no effect.) |
||
103 | if ($this->title->halign != 'left') { |
||
104 | $halign = $this->title->halign; |
||
105 | } |
||
106 | View Code Duplication | if ($this->title_adjust == 'high') { |
|
107 | $this->title->SetPos($x, $this->img->top_margin, $halign, 'top'); |
||
108 | } elseif ($this->title_adjust == 'middle' || $this->title_adjust == 'center') { |
||
109 | $this->title->SetPos($x, ($this->img->height - $this->img->top_margin - $this->img->bottom_margin) / 2 + $this->img->top_margin, $halign, "center"); |
||
110 | } elseif ($this->title_adjust == 'low') { |
||
111 | $this->title->SetPos($x, $this->img->height - $this->img->bottom_margin, $halign, 'bottom'); |
||
112 | } else { |
||
113 | Util\JpGraphError::RaiseL(25061, $this->title_adjust); //('Unknown alignment specified for Y-axis title. ('.$this->title_adjust.')'); |
||
1 ignored issue
–
show
|
|||
114 | } |
||
115 | } |
||
116 | $this->scale->ticks->Stroke($this->img, $this->scale, $pos); |
||
117 | if ($aStrokeLabels) { |
||
118 | if (!$this->hide_labels) { |
||
119 | $this->StrokeLabels($pos); |
||
120 | } |
||
121 | $this->title->Stroke($this->img); |
||
122 | } |
||
123 | } |
||
124 | |||
259 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: