| Conditions | 17 |
| Paths | 3 |
| Total Lines | 80 |
| Code Lines | 64 |
| 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 | $sour = new \PhpGedcom\Record\Sour(); |
||
| 32 | $sour->setSour($identifier); |
||
| 33 | |||
| 34 | $parser->getGedcom()->addSour($sour); |
||
| 35 | |||
| 36 | $parser->forward(); |
||
| 37 | |||
| 38 | while (!$parser->eof()) { |
||
| 39 | $record = $parser->getCurrentLineRecord(); |
||
| 40 | $currentDepth = (int) $record[0]; |
||
| 41 | $recordType = strtoupper(trim($record[1])); |
||
| 42 | |||
| 43 | if ($currentDepth <= $depth) { |
||
| 44 | $parser->back(); |
||
| 45 | break; |
||
| 46 | } |
||
| 47 | |||
| 48 | switch ($recordType) { |
||
| 49 | case 'DATA': |
||
| 50 | $sour->setData(\PhpGedcom\Parser\Sour\Data::parse($parser)); |
||
|
|
|||
| 51 | break; |
||
| 52 | case 'AUTH': |
||
| 53 | $sour->setAuth($parser->parseMultilineRecord()); |
||
| 54 | break; |
||
| 55 | case 'TITL': |
||
| 56 | $sour->setTitl($parser->parseMultilineRecord()); |
||
| 57 | break; |
||
| 58 | case 'ABBR': |
||
| 59 | $sour->setAbbr(trim($record[2])); |
||
| 60 | break; |
||
| 61 | case 'PUBL': |
||
| 62 | $sour->setPubl($parser->parseMultilineRecord()); |
||
| 63 | break; |
||
| 64 | case 'TEXT': |
||
| 65 | $sour->setText($parser->parseMultilineRecord()); |
||
| 66 | break; |
||
| 67 | case 'REPO': |
||
| 68 | $sour->setRepo(\PhpGedcom\Parser\Sour\Repo::parse($parser)); |
||
| 69 | break; |
||
| 70 | case 'REFN': |
||
| 71 | $refn = \PhpGedcom\Parser\Refn::parse($parser); |
||
| 72 | $sour->addRefn($refn); |
||
| 73 | break; |
||
| 74 | case 'RIN': |
||
| 75 | $sour->setRin(trim($record[2])); |
||
| 76 | break; |
||
| 77 | case 'CHAN': |
||
| 78 | $chan = \PhpGedcom\Parser\Chan::parse($parser); |
||
| 79 | $sour->setChan($chan); |
||
| 80 | break; |
||
| 81 | case 'NOTE': |
||
| 82 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); |
||
| 83 | if ($note) { |
||
| 84 | $sour->addNote($note); |
||
| 85 | } |
||
| 86 | break; |
||
| 87 | case 'OBJE': |
||
| 88 | $obje = \PhpGedcom\Parser\ObjeRef::parse($parser); |
||
| 89 | $sour->addObje($obje); |
||
| 90 | break; |
||
| 91 | default: |
||
| 92 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 93 | } |
||
| 94 | |||
| 95 | $parser->forward(); |
||
| 96 | } |
||
| 97 | |||
| 98 | return $sour; |
||
| 99 | } |
||
| 101 |