| Conditions | 15 | 
| Paths | 3 | 
| Total Lines | 73 | 
| Code Lines | 57 | 
| 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 | $repo = new \PhpGedcom\Record\Repo(); | ||
| 32 | $repo->setRepo($identifier); | ||
| 33 | |||
| 34 | $parser->getGedcom()->addRepo($repo); | ||
| 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 | $repo->setName(trim($record[2])); | ||
| 51 | break; | ||
| 52 | case 'ADDR': | ||
| 53 | $addr = \PhpGedcom\Parser\Addr::parse($parser); | ||
| 54 | $repo->setAddr($addr); | ||
| 55 | break; | ||
| 56 | case 'PHON': | ||
| 57 | $repo->addPhon(trim($record[2])); | ||
| 58 | break; | ||
| 59 | case 'EMAIL': | ||
| 60 | $repo->addEmail(trim($record[2])); | ||
| 61 | break; | ||
| 62 | case 'FAX': | ||
| 63 | $repo->addFax(trim($record[2])); | ||
| 64 | break; | ||
| 65 | case 'WWW': | ||
| 66 | $repo->addWww(trim($record[2])); | ||
| 67 | break; | ||
| 68 | case 'NOTE': | ||
| 69 |                     if ($note = \PhpGedcom\Parser\NoteRef::parse($parser)) { | ||
| 70 | $repo->addNote($note); | ||
| 71 | } | ||
| 72 | break; | ||
| 73 | case 'REFN': | ||
| 74 | $refn = \PhpGedcom\Parser\Refn::parse($parser); | ||
| 75 | $repo->addRefn($refn); | ||
| 76 | break; | ||
| 77 | case 'RIN': | ||
| 78 | $repo->setRin(trim($record[2])); | ||
| 79 | break; | ||
| 80 | case 'CHAN': | ||
| 81 | $chan = \PhpGedcom\Parser\Chan::parse($parser); | ||
| 82 | $repo->setChan($chan); | ||
| 83 | break; | ||
| 84 | default: | ||
| 85 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); | ||
| 86 | } | ||
| 87 | |||
| 88 | $parser->forward(); | ||
| 89 | } | ||
| 90 | |||
| 91 | return $repo; | ||
| 92 | } | ||
| 94 |