| Conditions | 67 |
| Paths | 3 |
| Total Lines | 168 |
| Code Lines | 147 |
| 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 |
||
| 19 | public static function parse(\PhpGedcom\Parser $parser) |
||
| 20 | { |
||
| 21 | $record = $parser->getCurrentLineRecord(); |
||
| 22 | $depth = (int) $record[0]; |
||
| 23 | if (isset($record[1])) { |
||
| 24 | $identifier = $parser->normalizeIdentifier($record[1]); |
||
| 25 | } else { |
||
| 26 | $parser->skipToNextLevel($depth); |
||
| 27 | |||
| 28 | return null; |
||
| 29 | } |
||
| 30 | |||
| 31 | $indi = new \PhpGedcom\Record\Indi(); |
||
| 32 | $indi->setId($identifier); |
||
| 33 | |||
| 34 | $parser->getGedcom()->addIndi($indi); |
||
| 35 | |||
| 36 | $parser->forward(); |
||
| 37 | |||
| 38 | while (!$parser->eof()) { |
||
| 39 | $record = $parser->getCurrentLineRecord(); |
||
| 40 | $recordType = strtoupper(trim($record[1])); |
||
| 41 | $currentDepth = (int) $record[0]; |
||
| 42 | |||
| 43 | if ($currentDepth <= $depth) { |
||
| 44 | $parser->back(); |
||
| 45 | break; |
||
| 46 | } |
||
| 47 | |||
| 48 | switch ($recordType) { |
||
| 49 | case '_UID': |
||
| 50 | $indi->setUid(trim($record[2])); |
||
| 51 | break; |
||
| 52 | case 'RESN': |
||
| 53 | $indi->setResn(trim($record[2])); |
||
| 54 | break; |
||
| 55 | case 'NAME': |
||
| 56 | $name = \PhpGedcom\Parser\Indi\Name::parse($parser); |
||
| 57 | $indi->addName($name); |
||
| 58 | break; |
||
| 59 | case 'SEX': |
||
| 60 | $indi->setSex(isset($record[2]) ? trim($record[2]) : ''); |
||
| 61 | break; |
||
| 62 | case 'ADOP': |
||
| 63 | case 'BIRT': |
||
| 64 | case 'BAPM': |
||
| 65 | case 'BARM': |
||
| 66 | case 'BASM': |
||
| 67 | case 'BLES': |
||
| 68 | case 'BURI': |
||
| 69 | case 'CENS': |
||
| 70 | case 'CHR': |
||
| 71 | case 'CHRA': |
||
| 72 | case 'CONF': |
||
| 73 | case 'CREM': |
||
| 74 | case 'DEAT': |
||
| 75 | case 'EMIG': |
||
| 76 | case 'FCOM': |
||
| 77 | case 'GRAD': |
||
| 78 | case 'IMMI': |
||
| 79 | case 'NATU': |
||
| 80 | case 'ORDN': |
||
| 81 | case 'RETI': |
||
| 82 | case 'PROB': |
||
| 83 | case 'WILL': |
||
| 84 | case 'EVEN': |
||
| 85 | $className = ucfirst(strtolower($recordType)); |
||
| 86 | $class = '\\PhpGedcom\\Parser\\Indi\\'.$className; |
||
| 87 | |||
| 88 | $event = $class::parse($parser); |
||
| 89 | $indi->addEven($event); |
||
| 90 | break; |
||
| 91 | case 'CAST': |
||
| 92 | case 'DSCR': |
||
| 93 | case 'EDUC': |
||
| 94 | case 'IDNO': |
||
| 95 | case 'NATI': |
||
| 96 | case 'NCHI': |
||
| 97 | case 'NMR': |
||
| 98 | case 'OCCU': |
||
| 99 | case 'PROP': |
||
| 100 | case 'RELI': |
||
| 101 | case 'RESI': |
||
| 102 | case 'SSN': |
||
| 103 | case 'TITL': |
||
| 104 | $className = ucfirst(strtolower($recordType)); |
||
| 105 | $class = '\\PhpGedcom\\Parser\\Indi\\'.$className; |
||
| 106 | |||
| 107 | $att = $class::parse($parser); |
||
| 108 | $indi->addAttr($att); |
||
| 109 | break; |
||
| 110 | case 'BAPL': |
||
| 111 | case 'CONL': |
||
| 112 | case 'ENDL': |
||
| 113 | case 'SLGC': |
||
| 114 | $className = ucfirst(strtolower($recordType)); |
||
| 115 | $class = '\\PhpGedcom\\Parser\\Indi\\'.$className; |
||
| 116 | |||
| 117 | $lds = $class::parse($parser); |
||
| 118 | $indi->{'add'.$recordType}[] = $lds; |
||
| 119 | break; |
||
| 120 | case 'FAMC': |
||
| 121 | $famc = \PhpGedcom\Parser\Indi\Famc::parse($parser); |
||
| 122 | if ($famc) { |
||
| 123 | $indi->addFamc($famc); |
||
| 124 | } |
||
| 125 | break; |
||
| 126 | case 'FAMS': |
||
| 127 | $fams = \PhpGedcom\Parser\Indi\Fams::parse($parser); |
||
| 128 | if ($fams) { |
||
| 129 | $indi->addFams($fams); |
||
| 130 | } |
||
| 131 | break; |
||
| 132 | case 'SUBM': |
||
| 133 | $indi->addSubm($parser->normalizeIdentifier($record[2])); |
||
| 134 | break; |
||
| 135 | case 'ASSO': |
||
| 136 | $asso = \PhpGedcom\Parser\Indi\Asso::parse($parser); |
||
| 137 | $indi->addAsso($asso); |
||
| 138 | break; |
||
| 139 | case 'ALIA': |
||
| 140 | $indi->addAlia($parser->normalizeIdentifier($record[2])); |
||
| 141 | break; |
||
| 142 | case 'ANCI': |
||
| 143 | $indi->addAnci($parser->normalizeIdentifier($record[2])); |
||
| 144 | break; |
||
| 145 | case 'DESI': |
||
| 146 | $indi->addDesi($parser->normalizeIdentifier($record[2])); |
||
| 147 | break; |
||
| 148 | case 'RFN': |
||
| 149 | $indi->setRfn(trim($record[2])); |
||
| 150 | break; |
||
| 151 | case 'AFN': |
||
| 152 | $indi->setAfn(trim($record[2])); |
||
| 153 | break; |
||
| 154 | case 'REFN': |
||
| 155 | $ref = \PhpGedcom\Parser\Refn::parse($parser); |
||
| 156 | $indi->addRefn($ref); |
||
| 157 | break; |
||
| 158 | case 'RIN': |
||
| 159 | $indi->setRin(trim($record[2])); |
||
| 160 | break; |
||
| 161 | case 'CHAN': |
||
| 162 | $chan = \PhpGedcom\Parser\Chan::parse($parser); |
||
| 163 | $indi->setChan($chan); |
||
|
|
|||
| 164 | break; |
||
| 165 | case 'NOTE': |
||
| 166 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); |
||
| 167 | if ($note) { |
||
| 168 | $indi->addNote($note); |
||
| 169 | } |
||
| 170 | break; |
||
| 171 | case 'SOUR': |
||
| 172 | $sour = \PhpGedcom\Parser\SourRef::parse($parser); |
||
| 173 | $indi->addSour($sour); |
||
| 174 | break; |
||
| 175 | case 'OBJE': |
||
| 176 | $obje = \PhpGedcom\Parser\ObjeRef::parse($parser); |
||
| 177 | $indi->addObje($obje); |
||
| 178 | break; |
||
| 179 | default: |
||
| 180 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 181 | } |
||
| 182 | |||
| 183 | $parser->forward(); |
||
| 184 | } |
||
| 185 | |||
| 186 | return $indi; |
||
| 187 | } |
||
| 189 |