Conditions | 16 |
Paths | 257 |
Total Lines | 78 |
Code Lines | 40 |
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(\Gedcom\Record\Obje &$obje) |
||
26 | { |
||
27 | $level = 0; |
||
28 | $output = ''; |
||
29 | $id = $obje->getId(); |
||
|
|||
30 | if ($id) { |
||
31 | $output .= $level.' '.$id." OBJE\n"; |
||
32 | } else { |
||
33 | return $output; |
||
34 | } |
||
35 | |||
36 | // level up |
||
37 | $level++; |
||
38 | |||
39 | // FORM |
||
40 | $form = $obje->getName(); |
||
41 | if ($form) { |
||
42 | $output .= $level.' FORM '.$form."\n"; |
||
43 | } |
||
44 | |||
45 | // TITL |
||
46 | $titl = $obje->getTitl(); |
||
47 | if ($titl) { |
||
48 | $output .= $level.' TITL '.$titl."\n"; |
||
49 | } |
||
50 | |||
51 | // OBJE |
||
52 | // This is same as FORM |
||
53 | |||
54 | // RIN |
||
55 | $rin = $obje->getRin(); |
||
56 | if ($rin) { |
||
57 | $output .= $level.' RIN '.$rin."\n"; |
||
58 | } |
||
59 | |||
60 | // REFN |
||
61 | $refn = $obje->getRefn(); |
||
62 | if (!empty($refn) && count($refn) > 0) { |
||
63 | foreach ($refn as $item) { |
||
64 | if ($item) { |
||
65 | $_convert = \Gedcom\Writer\Refn::convert($item, $level); |
||
66 | $output .= $_convert; |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | |||
71 | // BLOB |
||
72 | $blob = $obje->getBlob(); |
||
73 | if ($blob) { |
||
74 | $output .= $level.' BLOB '.$blob."\n"; |
||
75 | } |
||
76 | |||
77 | // NOTE |
||
78 | $note = $obje->getNote(); |
||
79 | if ($note && count($note) > 0) { |
||
80 | foreach ($note as $item) { |
||
81 | if ($item) { |
||
82 | $_convert = \Gedcom\Writer\NoteRef::convert($item, $level); |
||
83 | $output .= $_convert; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | // CHAN |
||
89 | $chan = $obje->getChan(); |
||
90 | if ($chan) { |
||
91 | $_convert = \Gedcom\Writer\Chan::convert($chan, $level); |
||
92 | $output .= $_convert; |
||
93 | } |
||
94 | |||
95 | // FILE |
||
96 | $file = $obje->getFile(); |
||
97 | if ($file) { |
||
98 | $output .= $level.' FILE '.$file."\n"; |
||
99 | } |
||
100 | |||
101 | // |
||
102 | return $output; |
||
103 | } |
||
105 |