| Conditions | 19 |
| Paths | 4 |
| Total Lines | 83 |
| Code Lines | 67 |
| 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(\Gedcom\Parser $parser) |
||
| 20 | { |
||
| 21 | $record = $parser->getCurrentLineRecord(); |
||
| 22 | $depth = (int) $record[0]; |
||
| 23 | |||
| 24 | $even = new \Gedcom\Record\Fam\Even(); |
||
| 25 | |||
| 26 | if (isset($record[1]) && strtoupper(trim($record[1])) != 'EVEN') { |
||
| 27 | $even->setType(trim($record[1])); |
||
|
|
|||
| 28 | } |
||
| 29 | |||
| 30 | $parser->forward(); |
||
| 31 | |||
| 32 | while (!$parser->eof()) { |
||
| 33 | $record = $parser->getCurrentLineRecord(); |
||
| 34 | $recordType = strtoupper(trim($record[1])); |
||
| 35 | $currentDepth = (int) $record[0]; |
||
| 36 | |||
| 37 | if ($currentDepth <= $depth) { |
||
| 38 | $parser->back(); |
||
| 39 | break; |
||
| 40 | } |
||
| 41 | |||
| 42 | switch ($recordType) { |
||
| 43 | case 'TYPE': |
||
| 44 | $even->setType(trim($record[2])); |
||
| 45 | break; |
||
| 46 | case 'DATE': |
||
| 47 | $dat = \Gedcom\Parser\Date::parse($parser); |
||
| 48 | $even->setDate($dat); |
||
| 49 | //$even->setDate(trim($record[2])); |
||
| 50 | break; |
||
| 51 | case 'PLAC': |
||
| 52 | $plac = \Gedcom\Parser\Plac::parse($parser); |
||
| 53 | $even->setPlac($plac); |
||
| 54 | break; |
||
| 55 | case 'ADDR': |
||
| 56 | $addr = \Gedcom\Parser\Addr::parse($parser); |
||
| 57 | $even->setAddr($addr); |
||
| 58 | break; |
||
| 59 | case 'PHON': |
||
| 60 | $phone = \Gedcom\Parser\Phon::parse($parser); |
||
| 61 | $even->addPhone($phone); |
||
| 62 | break; |
||
| 63 | case 'CAUS': |
||
| 64 | $even->setCaus(trim($record[2])); |
||
| 65 | break; |
||
| 66 | case 'AGE': |
||
| 67 | $even->setAge(trim($record[2])); |
||
| 68 | break; |
||
| 69 | case 'AGNC': |
||
| 70 | $even->setAgnc(trim($record[2])); |
||
| 71 | break; |
||
| 72 | case 'HUSB': |
||
| 73 | $husb = \Gedcom\Parser\Fam\Even\Husb::parse($parser); |
||
| 74 | $even->setHusb($husb); |
||
| 75 | break; |
||
| 76 | case 'WIFE': |
||
| 77 | $wife = \Gedcom\Parser\Fam\Even\Wife::parse($parser); |
||
| 78 | $even->setWife($wife); |
||
| 79 | break; |
||
| 80 | case 'SOUR': |
||
| 81 | $sour = \Gedcom\Parser\SourRef::parse($parser); |
||
| 82 | $even->addSour($sour); |
||
| 83 | break; |
||
| 84 | case 'OBJE': |
||
| 85 | $obje = \Gedcom\Parser\ObjeRef::parse($parser); |
||
| 86 | $even->addObje($obje); |
||
| 87 | break; |
||
| 88 | case 'NOTE': |
||
| 89 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||
| 90 | if ($note) { |
||
| 91 | $even->addNote($note); |
||
| 92 | } |
||
| 93 | break; |
||
| 94 | default: |
||
| 95 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||
| 96 | } |
||
| 97 | |||
| 98 | $parser->forward(); |
||
| 99 | } |
||
| 100 | |||
| 101 | return $even; |
||
| 102 | } |
||
| 104 |