Conditions | 35 |
Paths | 1968 |
Total Lines | 130 |
Code Lines | 75 |
Lines | 26 |
Ratio | 20 % |
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 |
||
128 | public function StrokeLabels($aPos, $aMinor = false, $aAbsLabel = false) |
||
129 | { |
||
130 | if (is_array($this->label_color) && count($this->label_color) > 3) { |
||
131 | $this->ticks_label_colors = $this->label_color; |
||
132 | $this->img->SetColor($this->label_color[0]); |
||
133 | } else { |
||
134 | $this->img->SetColor($this->label_color); |
||
135 | } |
||
136 | $this->img->SetFont($this->font_family, $this->font_style, $this->font_size); |
||
137 | $yoff = $this->img->GetFontHeight() / 2; |
||
138 | |||
139 | // Only draw labels at major tick marks |
||
140 | $nbr = count($this->scale->ticks->maj_ticks_label); |
||
141 | |||
142 | // We have the option to not-display the very first mark |
||
143 | // (Usefull when the first label might interfere with another |
||
144 | // axis.) |
||
145 | $i = $this->show_first_label ? 0 : 1; |
||
146 | if (!$this->show_last_label) { |
||
147 | --$nbr; |
||
148 | } |
||
149 | // Now run through all labels making sure we don't overshoot the end |
||
150 | // of the scale. |
||
151 | $ncolor = 0; |
||
152 | if (isset($this->ticks_label_colors)) { |
||
153 | $ncolor = count($this->ticks_label_colors); |
||
154 | } |
||
155 | while ($i < $nbr) { |
||
156 | // $tpos holds the absolute text position for the label |
||
157 | $tpos = $this->scale->ticks->maj_ticklabels_pos[$i]; |
||
158 | |||
159 | // Note. the $limit is only used for the x axis since we |
||
160 | // might otherwise overshoot if the scale has been centered |
||
161 | // This is due to us "loosing" the last tick mark if we center. |
||
162 | if ($this->scale->type == 'x' && $tpos > $this->img->width - $this->img->right_margin + 1) { |
||
163 | return; |
||
164 | } |
||
165 | // we only draw every $label_step label |
||
166 | if (($i % $this->label_step) == 0) { |
||
167 | |||
168 | // Set specific label color if specified |
||
169 | if ($ncolor > 0) { |
||
170 | $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]); |
||
171 | } |
||
172 | |||
173 | // If the label has been specified use that and in other case |
||
174 | // just label the mark with the actual scale value |
||
175 | $m = $this->scale->ticks->GetMajor(); |
||
176 | |||
177 | // ticks_label has an entry for each data point and is the array |
||
178 | // that holds the labels set by the user. If the user hasn't |
||
179 | // specified any values we use whats in the automatically asigned |
||
180 | // labels in the maj_ticks_label |
||
181 | if (isset($this->ticks_label[$i * $m])) { |
||
182 | $label = $this->ticks_label[$i * $m]; |
||
183 | } else { |
||
184 | if ($aAbsLabel) { |
||
185 | $label = abs($this->scale->ticks->maj_ticks_label[$i]); |
||
186 | } else { |
||
187 | $label = $this->scale->ticks->maj_ticks_label[$i]; |
||
188 | } |
||
189 | |||
190 | // We number the scale from 1 and not from 0 so increase by one |
||
191 | if ($this->scale->textscale && |
||
192 | $this->scale->ticks->label_formfunc == '' && |
||
193 | !$this->scale->ticks->HaveManualLabels()) { |
||
194 | ++$label; |
||
195 | } |
||
196 | } |
||
197 | |||
198 | if ($this->scale->type == "x") { |
||
199 | if ($this->labelPos == SIDE_DOWN) { |
||
200 | View Code Duplication | if ($this->label_angle == 0 || $this->label_angle == 90) { |
|
201 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
202 | $this->img->SetTextAlign('center', 'top'); |
||
203 | } else { |
||
204 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
205 | } |
||
206 | } else { |
||
207 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
208 | $this->img->SetTextAlign("right", "top"); |
||
209 | } else { |
||
210 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
211 | } |
||
212 | } |
||
213 | $this->img->StrokeText($tpos, $aPos + $this->tick_label_margin, $label, |
||
214 | $this->label_angle, $this->label_para_align); |
||
215 | } else { |
||
216 | View Code Duplication | if ($this->label_angle == 0 || $this->label_angle == 90) { |
|
217 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
218 | $this->img->SetTextAlign("center", "bottom"); |
||
219 | } else { |
||
220 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
221 | } |
||
222 | } else { |
||
223 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
224 | $this->img->SetTextAlign("right", "bottom"); |
||
225 | } else { |
||
226 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
227 | } |
||
228 | } |
||
229 | $this->img->StrokeText($tpos, $aPos - $this->tick_label_margin - 1, $label, |
||
230 | $this->label_angle, $this->label_para_align); |
||
231 | } |
||
232 | } else { |
||
233 | // scale->type == "y" |
||
234 | //if( $this->label_angle!=0 ) |
||
1 ignored issue
–
show
|
|||
235 | //Util\JpGraphError::Raise(" Labels at an angle are not supported on Y-axis"); |
||
1 ignored issue
–
show
|
|||
236 | if ($this->labelPos == SIDE_LEFT) { |
||
237 | // To the left of y-axis |
||
238 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
239 | $this->img->SetTextAlign("right", "center"); |
||
240 | } else { |
||
241 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
242 | } |
||
243 | $this->img->StrokeText($aPos - $this->tick_label_margin, $tpos, $label, $this->label_angle, $this->label_para_align); |
||
244 | } else { |
||
245 | // To the right of the y-axis |
||
246 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
247 | $this->img->SetTextAlign("left", "center"); |
||
248 | } else { |
||
249 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
250 | } |
||
251 | $this->img->StrokeText($aPos + $this->tick_label_margin, $tpos, $label, $this->label_angle, $this->label_para_align); |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | ++$i; |
||
256 | } |
||
257 | } |
||
258 | } |
||
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: