Conditions | 24 |
Paths | 4719 |
Total Lines | 122 |
Code Lines | 83 |
Lines | 27 |
Ratio | 22.13 % |
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 |
||
185 | private function printPersonPedigree($person, $count) { |
||
186 | if ($count >= $this->generations) { |
||
187 | return; |
||
188 | } |
||
189 | |||
190 | $genoffset = $this->generations; // handle pedigree n generations lines |
||
191 | //-- calculate how tall the lines should be |
||
192 | $lh = ($this->bhalfheight) * pow(2, ($genoffset - $count - 1)); |
||
193 | // |
||
194 | //Prints empty table columns for children w/o parents up to the max generation |
||
195 | //This allows vertical line spacing to be consistent |
||
196 | if (count($person->getChildFamilies()) == 0) { |
||
197 | echo '<table cellspacing="0" cellpadding="0" border="0" >'; |
||
198 | $this->printEmptyBox(); |
||
199 | |||
200 | //-- recursively get the father’s family |
||
201 | $this->printPersonPedigree($person, $count + 1); |
||
202 | echo '</td><td></tr>'; |
||
203 | $this->printEmptyBox(); |
||
204 | |||
205 | //-- recursively get the mother’s family |
||
206 | $this->printPersonPedigree($person, $count + 1); |
||
207 | echo '</td><td></tr></table>'; |
||
208 | } |
||
209 | |||
210 | // Empty box section done, now for regular pedigree |
||
211 | foreach ($person->getChildFamilies() as $family) { |
||
212 | echo '<table cellspacing="0" cellpadding="0" border="0" ><tr><td class="align-bottom">'; |
||
213 | // Determine line height for two or more spouces |
||
214 | // And then adjust the vertical line for the root person only |
||
215 | $famcount = 0; |
||
216 | if ($this->show_spouse === '1') { |
||
217 | // count number of spouses |
||
218 | $famcount += count($person->getSpouseFamilies()); |
||
219 | } |
||
220 | $savlh = $lh; // Save current line height |
||
221 | if ($count == 1 && $genoffset <= $famcount) { |
||
222 | $linefactor = 0; |
||
223 | // genoffset of 2 needs no adjustment |
||
224 | if ($genoffset > 2) { |
||
225 | $tblheight = $this->getBoxDimensions()->height + 8; |
||
226 | if ($genoffset == 3) { |
||
227 | if ($famcount == 3) { |
||
228 | $linefactor = $tblheight / 2; |
||
229 | } elseif ($famcount > 3) { |
||
230 | $linefactor = $tblheight; |
||
231 | } |
||
232 | } |
||
233 | View Code Duplication | if ($genoffset == 4) { |
|
234 | if ($famcount == 4) { |
||
235 | $linefactor = $tblheight; |
||
236 | } elseif ($famcount > 4) { |
||
237 | $linefactor = ($famcount - $genoffset) * ($tblheight * 1.5); |
||
238 | } |
||
239 | } |
||
240 | View Code Duplication | if ($genoffset == 5) { |
|
241 | if ($famcount == 5) { |
||
242 | $linefactor = 0; |
||
243 | } elseif ($famcount > 5) { |
||
244 | $linefactor = $tblheight * ($famcount - $genoffset); |
||
245 | } |
||
246 | } |
||
247 | } |
||
248 | $lh = (($famcount - 1) * ($this->getBoxDimensions()->height) - ($linefactor)); |
||
249 | if ($genoffset > 5) { |
||
250 | $lh = $savlh; |
||
251 | } |
||
252 | } |
||
253 | echo '<img class="line3 pvline" src="', Theme::theme()->parameter('image-vline'), '" width="3" height="', $lh, '"></td>', |
||
254 | '<td>', |
||
255 | '<img class="linef2" src="', Theme::theme()->parameter('image-hline'), '" height="3"></td>', |
||
256 | '<td>'; |
||
257 | $lh = $savlh; // restore original line height |
||
258 | //-- print the father box |
||
259 | FunctionsPrint::printPedigreePerson($family->getHusband()); |
||
260 | echo '</td>'; |
||
261 | if ($family->getHusband()) { |
||
262 | echo '<td>'; |
||
263 | //-- recursively get the father’s family |
||
264 | $this->printPersonPedigree($family->getHusband(), $count + 1); |
||
265 | echo '</td>'; |
||
266 | } else { |
||
267 | echo '<td>'; |
||
268 | if ($genoffset > $count) { |
||
269 | echo '<table cellspacing="0" cellpadding="0" border="0" >'; |
||
270 | for ($i = 1; $i < (pow(2, ($genoffset) - $count) / 2); $i++) { |
||
271 | $this->printEmptyBox(); |
||
272 | echo '</tr>'; |
||
273 | } |
||
274 | echo '</table>'; |
||
275 | } |
||
276 | } |
||
277 | echo '</tr><tr>', |
||
278 | '<td class="align-top"><img class="pvline" src="', Theme::theme()->parameter('image-vline'), '" width="3" height="', $lh, '"></td>', |
||
279 | '<td><img class="linef3" src="', Theme::theme()->parameter('image-hline'), '" height="3"></td>', |
||
280 | '<td>'; |
||
281 | //-- print the mother box |
||
282 | FunctionsPrint::printPedigreePerson($family->getWife()); |
||
283 | echo '</td>'; |
||
284 | if ($family->getWife()) { |
||
285 | echo '<td>'; |
||
286 | //-- recursively print the mother’s family |
||
287 | $this->printPersonPedigree($family->getWife(), $count + 1); |
||
288 | echo '</td>'; |
||
289 | View Code Duplication | } else { |
|
290 | echo '<td>'; |
||
291 | if ($count < $genoffset - 1) { |
||
292 | echo '<table cellspacing="0" cellpadding="0" border="0" >'; |
||
293 | for ($i = 1; $i < (pow(2, ($genoffset - 1) - $count) / 2) + 1; $i++) { |
||
294 | $this->printEmptyBox(); |
||
295 | echo '</tr>'; |
||
296 | $this->printEmptyBox(); |
||
297 | echo '</tr>'; |
||
298 | } |
||
299 | echo '</table>'; |
||
300 | } |
||
301 | } |
||
302 | echo '</tr>', |
||
303 | '</table>'; |
||
304 | break; |
||
305 | } |
||
306 | } |
||
307 | |||
383 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.