| Conditions | 29 | 
| Paths | 3 | 
| Total Lines | 103 | 
| Code Lines | 85 | 
| 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 | ||
| 32 | public static function parse(\PhpGedcom\Parser $parser) | ||
| 33 |     { | ||
| 34 | $record = $parser->getCurrentLineRecord(); | ||
| 35 | $depth = (int) $record[0]; | ||
| 36 |         if (isset($record[1])) { | ||
| 37 | $identifier = $parser->normalizeIdentifier($record[1]); | ||
| 38 |         } else { | ||
| 39 | $parser->skipToNextLevel($depth); | ||
| 40 | |||
| 41 | return null; | ||
| 42 | } | ||
| 43 | |||
| 44 | $fam = new \PhpGedcom\Record\Fam(); | ||
| 45 | $fam->setId($identifier); | ||
|  | |||
| 46 | |||
| 47 | $parser->getGedcom()->addFam($fam); | ||
| 48 | |||
| 49 | $parser->forward(); | ||
| 50 | |||
| 51 |         while (!$parser->eof()) { | ||
| 52 | $record = $parser->getCurrentLineRecord(); | ||
| 53 | $currentDepth = (int) $record[0]; | ||
| 54 | $recordType = strtoupper(trim($record[1])); | ||
| 55 | |||
| 56 |             if ($currentDepth <= $depth) { | ||
| 57 | $parser->back(); | ||
| 58 | break; | ||
| 59 | } | ||
| 60 | |||
| 61 |             switch ($recordType) { | ||
| 62 | case 'RESN': | ||
| 63 | $fam->setResn(trim($record[2])); | ||
| 64 | break; | ||
| 65 | case 'EVEN': | ||
| 66 | case 'ANUL': | ||
| 67 | case 'CENS': | ||
| 68 | case 'DIV': | ||
| 69 | case 'DIVF': | ||
| 70 | case 'ENGA': | ||
| 71 | case 'MARR': | ||
| 72 | case 'MARB': | ||
| 73 | case 'MARC': | ||
| 74 | case 'MARL': | ||
| 75 | case 'MARS': | ||
| 76 | $className = ucfirst(strtolower($recordType)); | ||
| 77 | $class = '\\PhpGedcom\\Parser\\Fam\\'.$className; | ||
| 78 | |||
| 79 | $even = $class::parse($parser); | ||
| 80 | $fam->addEven($even); | ||
| 81 | break; | ||
| 82 | case 'HUSB': | ||
| 83 | $fam->setHusb($parser->normalizeIdentifier($record[2])); | ||
| 84 | break; | ||
| 85 | case 'WIFE': | ||
| 86 | $fam->setWife($parser->normalizeIdentifier($record[2])); | ||
| 87 | break; | ||
| 88 | case 'CHIL': | ||
| 89 | $fam->addChil($parser->normalizeIdentifier($record[2])); | ||
| 90 | break; | ||
| 91 | case 'NCHI': | ||
| 92 | $fam->setNchi(trim($record[2])); | ||
| 93 | break; | ||
| 94 | case 'SUBM': | ||
| 95 | $fam->addSubm($parser->normalizeIdentifier($record[2])); | ||
| 96 | break; | ||
| 97 | case 'SLGS': | ||
| 98 | $slgs = \PhpGedcom\Parser\Fam\Slgs::parse($parser); | ||
| 99 | $fam->addSlgs($slgs); | ||
| 100 | break; | ||
| 101 | case 'REFN': | ||
| 102 | $ref = \PhpGedcom\Parser\Refn::parse($parser); | ||
| 103 | $fam->addRefn($ref); | ||
| 104 | break; | ||
| 105 | case 'RIN': | ||
| 106 | $fam->setRin(trim($record[2])); | ||
| 107 | break; | ||
| 108 | case 'CHAN': | ||
| 109 | $chan = \PhpGedcom\Parser\Chan::parse($parser); | ||
| 110 | $fam->setChan($chan); | ||
| 111 | break; | ||
| 112 | case 'NOTE': | ||
| 113 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); | ||
| 114 |                     if ($note) { | ||
| 115 | $fam->addNote($note); | ||
| 116 | } | ||
| 117 | break; | ||
| 118 | case 'SOUR': | ||
| 119 | $sour = \PhpGedcom\Parser\SourRef::parse($parser); | ||
| 120 | $fam->addSour($sour); | ||
| 121 | break; | ||
| 122 | case 'OBJE': | ||
| 123 | $obje = \PhpGedcom\Parser\ObjeRef::parse($parser); | ||
| 124 | $fam->addObje($obje); | ||
| 125 | break; | ||
| 126 | |||
| 127 | default: | ||
| 128 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); | ||
| 129 | } | ||
| 130 | |||
| 131 | $parser->forward(); | ||
| 132 | } | ||
| 133 | |||
| 134 | return $fam; | ||
| 135 | } | ||
| 137 |