Conditions | 21 |
Paths | 513 |
Total Lines | 85 |
Code Lines | 48 |
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 |
||
27 | public static function convert(\PhpGedcom\Record\Subm &$subm) |
||
28 | { |
||
29 | $level = 0; |
||
30 | $output = ""; |
||
31 | $_subm = $subm->getSubn(); |
||
|
|||
32 | if(empty($_subm)){ |
||
33 | return $output; |
||
34 | }else{ |
||
35 | $output.=$level." ".$_subm." SUBM "."\n"; |
||
36 | } |
||
37 | // level up |
||
38 | $level++; |
||
39 | |||
40 | // NAME |
||
41 | $name = $subm->getName(); |
||
42 | if(!empty($name)){ |
||
43 | $output.=$level." NAME ".$name."\n"; |
||
44 | } |
||
45 | // $chan |
||
46 | $chan = $subm->getChan(); |
||
47 | if($chan){ |
||
48 | $_convert = \PhpGedcom\Writer\Chan::convert($chan, $level); |
||
49 | $output.=$_convert; |
||
50 | } |
||
51 | |||
52 | // $addr |
||
53 | $addr = $subm->getAddr(); |
||
54 | if($addr){ |
||
55 | $_convert = \PhpGedcom\Writer\Addr::convert($addr, $level); |
||
56 | $output.=$_convert; |
||
57 | } |
||
58 | |||
59 | // $rin |
||
60 | $rin = $subm->getRin(); |
||
61 | if(!empty($rin)){ |
||
62 | $output.=$level." RIN ".$rin."\n"; |
||
63 | } |
||
64 | |||
65 | // $rfn |
||
66 | $rfn = $subm->getRfn(); |
||
67 | if(!empty($rfn)){ |
||
68 | $output.=$level." RFN ".$rfn."\n"; |
||
69 | } |
||
70 | |||
71 | // $lang = array() |
||
72 | $langs = $subm->getLang(); |
||
73 | if(!empty($langs) && count($langs) > 0){ |
||
74 | foreach($langs as $item){ |
||
75 | if($item){ |
||
76 | $_convert = $level." LANG ".$item."\n"; |
||
77 | $output.=$_convert; |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // $phon = array() |
||
83 | $phon = $subm->getLang(); |
||
84 | if(!empty($phon) && count($phon) > 0){ |
||
85 | foreach($phon as $item){ |
||
86 | if($item){ |
||
87 | $_convert = \PhpGedcom\Writer\Phon::convert($item, $level); |
||
88 | $output.= $_convert; |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | |||
93 | // $obje = array() |
||
94 | $obje = $subm->getObje(); |
||
95 | if(!empty($obje) && count($obje) > 0){ |
||
96 | foreach($obje as $item){ |
||
97 | $_convert = \PhpGedcom\Writer\ObjeRef::convert($item, $level); |
||
98 | $output.=$_convert; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // note |
||
103 | $note = $subm->getNote(); |
||
104 | if(!empty($note) && count($note) > 0){ |
||
105 | foreach($note as $item){ |
||
106 | $_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level); |
||
107 | $output.=$_convert; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | return $output; |
||
112 | } |
||
114 |