| Conditions | 14 |
| Paths | 257 |
| Total Lines | 61 |
| Code Lines | 35 |
| 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\Indi\Name &$name, $level = 0) |
||
| 26 | { |
||
| 27 | $output = ''; |
||
| 28 | // NAME |
||
| 29 | $_name = $name->getName(); |
||
| 30 | if (empty($_name)) { |
||
| 31 | return $output; |
||
| 32 | } |
||
| 33 | $output .= $level.' NAME '.$_name."\n"; |
||
| 34 | // level up |
||
| 35 | $level++; |
||
| 36 | |||
| 37 | // NPFX |
||
| 38 | $npfx = $name->getNpfx(); |
||
| 39 | if (!empty($npfx)) { |
||
| 40 | $output .= $level.' NPFX '.$npfx."\n"; |
||
| 41 | } |
||
| 42 | |||
| 43 | // GIVN |
||
| 44 | $givn = $name->getGivn(); |
||
| 45 | if (!empty($givn)) { |
||
| 46 | $output .= $level.' GIVN '.$givn."\n"; |
||
| 47 | } |
||
| 48 | // NICK |
||
| 49 | $nick = $name->getNick(); |
||
| 50 | if (!empty($nick)) { |
||
| 51 | $output .= $level.' NICK '.$nick."\n"; |
||
| 52 | } |
||
| 53 | // SPFX |
||
| 54 | $spfx = $name->getSpfx(); |
||
| 55 | if (!empty($spfx)) { |
||
| 56 | $output .= $level.' SPFX '.$spfx."\n"; |
||
| 57 | } |
||
| 58 | // SURN |
||
| 59 | $surn = $name->getSurn(); |
||
| 60 | if (!empty($surn)) { |
||
| 61 | $output .= $level.' SURN '.$surn."\n"; |
||
| 62 | } |
||
| 63 | // NSFX |
||
| 64 | $nsfx = $name->getNsfx(); |
||
| 65 | if (!empty($nsfx)) { |
||
| 66 | $output .= $level.' NSFX '.$nsfx."\n"; |
||
| 67 | } |
||
| 68 | // SOUR |
||
| 69 | $sour = $name->getSour(); |
||
|
|
|||
| 70 | if (!empty($sour) && count($sour) > 0) { |
||
| 71 | foreach ($sour as $item) { |
||
| 72 | $_convert = \Gedcom\Writer\SourRef::convert($item, $level); |
||
| 73 | $output .= $_convert; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | // note |
||
| 77 | $note = $name->getSour(); |
||
| 78 | if (!empty($note) && count($note) > 0) { |
||
| 79 | foreach ($note as $item) { |
||
| 80 | $_convert = \Gedcom\Writer\NoteRef::convert($item, $level); |
||
| 81 | $output .= $_convert; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return $output; |
||
| 86 | } |
||
| 88 |