| Conditions | 17 |
| Paths | 5 |
| Total Lines | 80 |
| Code Lines | 63 |
| 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 | $className = '\\PhpGedcom\\Record\\Indi\\'.ucfirst(strtolower(trim($record[1]))); |
||
| 25 | $attr = new $className(); |
||
| 26 | |||
| 27 | $attr->setType(trim($record[1])); |
||
| 28 | } else { |
||
| 29 | $parser->skipToNextLevel($depth); |
||
| 30 | |||
| 31 | return null; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (isset($record[2])) { |
||
| 35 | $attr->setAttr(trim($record[2])); |
||
| 36 | } |
||
| 37 | |||
| 38 | $parser->forward(); |
||
| 39 | |||
| 40 | while (!$parser->eof()) { |
||
| 41 | $record = $parser->getCurrentLineRecord(); |
||
| 42 | $recordType = strtoupper(trim($record[1])); |
||
| 43 | $currentDepth = (int) $record[0]; |
||
| 44 | |||
| 45 | if ($currentDepth <= $depth) { |
||
| 46 | $parser->back(); |
||
| 47 | break; |
||
| 48 | } |
||
| 49 | |||
| 50 | switch ($recordType) { |
||
| 51 | case 'TYPE': |
||
| 52 | $attr->setType(trim($record[2])); |
||
| 53 | break; |
||
| 54 | case 'DATE': |
||
| 55 | $attr->setDate(trim($record[2])); |
||
| 56 | break; |
||
| 57 | case 'PLAC': |
||
| 58 | $plac = \PhpGedcom\Parser\Indi\Even\Plac::parse($parser); |
||
| 59 | $attr->setPlac($plac); |
||
| 60 | break; |
||
| 61 | case 'ADDR': |
||
| 62 | $attr->setAddr(\PhpGedcom\Parser\Addr::parse($parser)); |
||
| 63 | break; |
||
| 64 | case 'PHON': |
||
| 65 | $phone = \PhpGedcom\Parser\Phon::parse($parser); |
||
| 66 | $attr->addPhon($phone); |
||
| 67 | break; |
||
| 68 | case 'CAUS': |
||
| 69 | $attr->setCaus(trim($record[2])); |
||
| 70 | break; |
||
| 71 | case 'AGE': |
||
| 72 | $attr->setAge(trim($record[2])); |
||
| 73 | break; |
||
| 74 | case 'AGNC': |
||
| 75 | $attr->setAgnc(trim($record[2])); |
||
| 76 | break; |
||
| 77 | case 'SOUR': |
||
| 78 | $sour = \PhpGedcom\Parser\SourRef::parse($parser); |
||
| 79 | $attr->addSour($sour); |
||
| 80 | break; |
||
| 81 | case 'OBJE': |
||
| 82 | $obje = \PhpGedcom\Parser\ObjeRef::parse($parser); |
||
| 83 | $attr->addObje($obje); |
||
| 84 | break; |
||
| 85 | case 'NOTE': |
||
| 86 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); |
||
| 87 | if ($note) { |
||
| 88 | $attr->addNote($note); |
||
| 89 | } |
||
| 90 | break; |
||
| 91 | default: |
||
| 92 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 93 | } |
||
| 94 | |||
| 95 | $parser->forward(); |
||
| 96 | } |
||
| 97 | |||
| 98 | return $attr; |
||
| 99 | } |
||
| 101 |