| Conditions | 25 |
| Paths | 3 |
| Total Lines | 84 |
| Code Lines | 68 |
| 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 | $subm = new \PhpGedcom\Record\Subm(); |
||
| 32 | $subm->setSubm($identifier); |
||
| 33 | |||
| 34 | $parser->getGedcom()->addSubm($subm); |
||
| 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 'NAME': |
||
| 50 | $subm->setName(isset($record[2]) ? trim($record[2]) : ''); |
||
| 51 | break; |
||
| 52 | case 'ADDR': |
||
| 53 | $addr = \PhpGedcom\Parser\Addr::parse($parser); |
||
| 54 | $subm->setAddr($addr); |
||
| 55 | break; |
||
| 56 | case 'PHON': |
||
| 57 | $phone = isset($record[2]) ? trim($record[2]) : ''; |
||
| 58 | $subm->addPhon($phone); |
||
|
|
|||
| 59 | break; |
||
| 60 | case 'EMAIL': |
||
| 61 | $email = isset($record[2]) ? trim($record[2]) : ''; |
||
| 62 | $subm->addEmail($email); |
||
| 63 | break; |
||
| 64 | case 'FAX': |
||
| 65 | $fax = isset($record[2]) ? trim($record[2]) : ''; |
||
| 66 | $subm->addFax($fax); |
||
| 67 | break; |
||
| 68 | case 'WWW': |
||
| 69 | $www = isset($record[2]) ? trim($record[2]) : ''; |
||
| 70 | $subm->addWww($www); |
||
| 71 | break; |
||
| 72 | case 'NOTE': |
||
| 73 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); |
||
| 74 | if ($note) { |
||
| 75 | $subm->addNote($note); |
||
| 76 | } |
||
| 77 | break; |
||
| 78 | case 'OBJE': |
||
| 79 | $obje = \PhpGedcom\Parser\ObjeRef::parse($parser); |
||
| 80 | $subm->addObje($obje); |
||
| 81 | break; |
||
| 82 | case 'CHAN': |
||
| 83 | $chan = \PhpGedcom\Parser\Chan::parse($parser); |
||
| 84 | $subm->setChan($chan); |
||
| 85 | break; |
||
| 86 | case 'RIN': |
||
| 87 | $subm->setRin(isset($record[2]) ? trim($record[2]) : ''); |
||
| 88 | break; |
||
| 89 | case 'RFN': |
||
| 90 | $subm->setRfn(isset($record[2]) ? trim($record[2]) : ''); |
||
| 91 | break; |
||
| 92 | case 'LANG': |
||
| 93 | $subm->addLang(isset($record[2]) ? trim($record[2]) : ''); |
||
| 94 | break; |
||
| 95 | default: |
||
| 96 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 97 | } |
||
| 98 | |||
| 99 | $parser->forward(); |
||
| 100 | } |
||
| 101 | |||
| 102 | return $subm; |
||
| 103 | } |
||
| 105 |