Conditions | 13 |
Paths | 33 |
Total Lines | 54 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
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 |
||
25 | public static function convert(\PhpGedcom\Record\Note &$note) |
||
26 | { |
||
27 | $level = 0; |
||
28 | $output = ''; |
||
29 | $id = $note->getId(); |
||
|
|||
30 | if (!empty($id)) { |
||
31 | $output .= $level.' '.$id.' '." NOTE \n"; |
||
32 | } else { |
||
33 | return $output; |
||
34 | } |
||
35 | |||
36 | // Level Up |
||
37 | $level++; |
||
38 | // RIN |
||
39 | $rin = $note->getRin(); |
||
40 | if ($rin) { |
||
41 | $output .= $level.' RIN '.$rin."\n"; |
||
42 | } |
||
43 | |||
44 | // cont |
||
45 | $cont = $note->getNote(); |
||
46 | if ($cont) { |
||
47 | $output .= $level.' CONT '.$cont."\n"; |
||
48 | } |
||
49 | |||
50 | // REFN |
||
51 | $refn = $note->getRefn(); |
||
52 | if (!empty($refn) && count($refn) > 0) { |
||
53 | foreach ($refn as $item) { |
||
54 | if ($item) { |
||
55 | $_convert = \PhpGedcom\Writer\Refn::convert($item, $level); |
||
56 | $output .= $_convert; |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | // CHAN |
||
61 | $chan = $note->getChan(); |
||
62 | if ($chan) { |
||
63 | $_convert = \PhpGedcom\Writer\Chan::convert($chan, $level); |
||
64 | $output .= $_convert; |
||
65 | } |
||
66 | |||
67 | // SOUR array |
||
68 | $sour = $note->getSour(); |
||
69 | if (!empty($sour) && count($sour) > 0) { |
||
70 | foreach ($sour as $item) { |
||
71 | if ($item) { |
||
72 | $_convert = \PhpGedcom\Writer\SourRef::convert($item, $level); |
||
73 | $output .= $_convert; |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
78 | return $output; |
||
79 | } |
||
81 |