| Conditions | 68 |
| Paths | 3 |
| Total Lines | 184 |
| Code Lines | 161 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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(\Gedcom\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 \Gedcom\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 | if ($recordType == 'BURI') { |
||
| 49 | $a = ''; |
||
|
|
|||
| 50 | } |
||
| 51 | |||
| 52 | switch ($recordType) { |
||
| 53 | case '_UID': |
||
| 54 | $indi->setUid(trim($record[2])); |
||
| 55 | break; |
||
| 56 | case 'RESN': |
||
| 57 | $indi->setResn(trim($record[2])); |
||
| 58 | break; |
||
| 59 | case 'NAME': |
||
| 60 | $name = \Gedcom\Parser\Indi\Name::parse($parser); |
||
| 61 | $indi->addName($name); |
||
| 62 | break; |
||
| 63 | case 'SEX': |
||
| 64 | $indi->setSex(isset($record[2]) ? trim($record[2]) : ''); |
||
| 65 | break; |
||
| 66 | case 'ADOP': |
||
| 67 | case 'BIRT': |
||
| 68 | $birt = \Gedcom\Parser\Birt::parse($parser); |
||
| 69 | $indi->setBirt($birt); |
||
| 70 | break; |
||
| 71 | case 'BAPM': |
||
| 72 | case 'BARM': |
||
| 73 | case 'BASM': |
||
| 74 | case 'BLES': |
||
| 75 | case 'BURI': |
||
| 76 | $buri = \Gedcom\Parser\Buri::parse($parser); |
||
| 77 | $indi->setBuri($buri); |
||
| 78 | break; |
||
| 79 | case 'CENS': |
||
| 80 | case 'CHR': |
||
| 81 | $chr = \Gedcom\Parser\Chr::parse($parser); |
||
| 82 | $indi->setChr($chr); |
||
| 83 | break; |
||
| 84 | case 'CHRA': |
||
| 85 | case 'CONF': |
||
| 86 | case 'CREM': |
||
| 87 | case 'DEAT': |
||
| 88 | $deat = \Gedcom\Parser\Deat::parse($parser); |
||
| 89 | $indi->setDeat($deat); |
||
| 90 | break; |
||
| 91 | case 'EMIG': |
||
| 92 | case 'FCOM': |
||
| 93 | case 'GRAD': |
||
| 94 | case 'IMMI': |
||
| 95 | case 'NATU': |
||
| 96 | case 'ORDN': |
||
| 97 | case 'RETI': |
||
| 98 | case 'PROB': |
||
| 99 | case 'WILL': |
||
| 100 | case 'EVEN': |
||
| 101 | $className = ucfirst(strtolower($recordType)); |
||
| 102 | $class = '\\Gedcom\\Parser\\Indi\\'.$className; |
||
| 103 | |||
| 104 | $event = $class::parse($parser); |
||
| 105 | $indi->addEven($event); |
||
| 106 | break; |
||
| 107 | case 'CAST': |
||
| 108 | case 'DSCR': |
||
| 109 | case 'EDUC': |
||
| 110 | case 'IDNO': |
||
| 111 | case 'NATI': |
||
| 112 | case 'NCHI': |
||
| 113 | case 'NMR': |
||
| 114 | case 'OCCU': |
||
| 115 | case 'PROP': |
||
| 116 | case 'RELI': |
||
| 117 | case 'RESI': |
||
| 118 | case 'SSN': |
||
| 119 | case 'TITL': |
||
| 120 | $className = ucfirst(strtolower($recordType)); |
||
| 121 | $class = '\\Gedcom\\Parser\\Indi\\'.$className; |
||
| 122 | |||
| 123 | $att = $class::parse($parser); |
||
| 124 | $indi->addAttr($att); |
||
| 125 | break; |
||
| 126 | case 'BAPL': |
||
| 127 | case 'CONL': |
||
| 128 | case 'ENDL': |
||
| 129 | case 'SLGC': |
||
| 130 | $className = ucfirst(strtolower($recordType)); |
||
| 131 | $class = '\\Gedcom\\Parser\\Indi\\'.$className; |
||
| 132 | |||
| 133 | $lds = $class::parse($parser); |
||
| 134 | $indi->{'add'.$recordType}[] = $lds; |
||
| 135 | break; |
||
| 136 | case 'FAMC': |
||
| 137 | $famc = \Gedcom\Parser\Indi\Famc::parse($parser); |
||
| 138 | if ($famc) { |
||
| 139 | $indi->addFamc($famc); |
||
| 140 | } |
||
| 141 | break; |
||
| 142 | case 'FAMS': |
||
| 143 | $fams = \Gedcom\Parser\Indi\Fams::parse($parser); |
||
| 144 | if ($fams) { |
||
| 145 | $indi->addFams($fams); |
||
| 146 | } |
||
| 147 | break; |
||
| 148 | case 'SUBM': |
||
| 149 | $indi->addSubm($parser->normalizeIdentifier($record[2])); |
||
| 150 | break; |
||
| 151 | case 'ASSO': |
||
| 152 | $asso = \Gedcom\Parser\Indi\Asso::parse($parser); |
||
| 153 | $indi->addAsso($asso); |
||
| 154 | break; |
||
| 155 | case 'ALIA': |
||
| 156 | $indi->addAlia($parser->normalizeIdentifier($record[2])); |
||
| 157 | break; |
||
| 158 | case 'ANCI': |
||
| 159 | $indi->addAnci($parser->normalizeIdentifier($record[2])); |
||
| 160 | break; |
||
| 161 | case 'DESI': |
||
| 162 | $indi->addDesi($parser->normalizeIdentifier($record[2])); |
||
| 163 | break; |
||
| 164 | case 'RFN': |
||
| 165 | $indi->setRfn(trim($record[2])); |
||
| 166 | break; |
||
| 167 | case 'AFN': |
||
| 168 | $indi->setAfn(trim($record[2])); |
||
| 169 | break; |
||
| 170 | case 'REFN': |
||
| 171 | $ref = \Gedcom\Parser\Refn::parse($parser); |
||
| 172 | $indi->addRefn($ref); |
||
| 173 | break; |
||
| 174 | case 'RIN': |
||
| 175 | $indi->setRin(trim($record[2])); |
||
| 176 | break; |
||
| 177 | case 'CHAN': |
||
| 178 | $chan = \Gedcom\Parser\Chan::parse($parser); |
||
| 179 | $indi->setChan($chan); |
||
| 180 | break; |
||
| 181 | case 'NOTE': |
||
| 182 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||
| 183 | if ($note) { |
||
| 184 | $indi->addNote($note); |
||
| 185 | } |
||
| 186 | break; |
||
| 187 | case 'SOUR': |
||
| 188 | $sour = \Gedcom\Parser\SourRef::parse($parser); |
||
| 189 | $indi->addSour($sour); |
||
| 190 | break; |
||
| 191 | case 'OBJE': |
||
| 192 | $obje = \Gedcom\Parser\ObjeRef::parse($parser); |
||
| 193 | $indi->addObje($obje); |
||
| 194 | break; |
||
| 195 | default: |
||
| 196 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||
| 197 | } |
||
| 198 | |||
| 199 | $parser->forward(); |
||
| 200 | } |
||
| 201 | |||
| 202 | return $indi; |
||
| 203 | } |
||
| 205 |