| Conditions | 15 |
| Paths | 129 |
| Total Lines | 70 |
| Code Lines | 39 |
| 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\Repo &$repo) |
||
| 26 | { |
||
| 27 | $level = 0; |
||
| 28 | $output = ''; |
||
| 29 | $_repo = $repo->getRepo(); |
||
| 30 | if ($_repo) { |
||
| 31 | $output .= $level.' '.$_repo." REPO\n"; |
||
| 32 | } else { |
||
| 33 | return $output; |
||
| 34 | } |
||
| 35 | |||
| 36 | // level up |
||
| 37 | $level++; |
||
| 38 | |||
| 39 | //NAME |
||
| 40 | $name = $repo->getName(); |
||
| 41 | if ($name) { |
||
| 42 | $output .= $level.' NAME '.$name."\n"; |
||
| 43 | } |
||
| 44 | |||
| 45 | // ADDR |
||
| 46 | $addr = $repo->getAddr(); |
||
| 47 | if ($addr) { |
||
|
|
|||
| 48 | $_convert = \Gedcom\Writer\Addr::convert($addr, $level); |
||
| 49 | $output .= $_convert; |
||
| 50 | } |
||
| 51 | |||
| 52 | // PHON |
||
| 53 | $phon = $repo->getPhon(); |
||
| 54 | if ($phon) { |
||
| 55 | $_convert = \Gedcom\Writer\Phon::convert($phon, $level); |
||
| 56 | $output .= $_convert; |
||
| 57 | } |
||
| 58 | |||
| 59 | // NOTE array |
||
| 60 | $note = $repo->getNote(); |
||
| 61 | if ($note && count($note) > 0) { |
||
| 62 | foreach ($note as $item) { |
||
| 63 | if ($item) { |
||
| 64 | $_convert = \Gedcom\Writer\NoteRef::convert($item, $level); |
||
| 65 | $output .= $_convert; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | // REFN |
||
| 71 | $refn = $repo->getRefn(); |
||
| 72 | if (!empty($refn) && count($refn) > 0) { |
||
| 73 | foreach ($refn as $item) { |
||
| 74 | if ($item) { |
||
| 75 | $_convert = \Gedcom\Writer\Refn::convert($item, $level); |
||
| 76 | $output .= $_convert; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | // CHAN |
||
| 82 | $chan = $repo->getChan(); |
||
| 83 | if ($chan) { |
||
| 84 | $_convert = \Gedcom\Writer\Chan::convert($chan, $level); |
||
| 85 | $output .= $_convert; |
||
| 86 | } |
||
| 87 | |||
| 88 | // RIN |
||
| 89 | $rin = $repo->getRin(); |
||
| 90 | if ($rin) { |
||
| 91 | $output .= $level.' RIN '.$rin."\n"; |
||
| 92 | } |
||
| 93 | |||
| 94 | return $output; |
||
| 95 | } |
||
| 97 |