| Conditions | 11 | 
| Paths | 3 | 
| Total Lines | 65 | 
| Code Lines | 46 | 
| 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 | $obje = new \PhpGedcom\Record\Obje(); | ||
| 32 | $obje->setId($identifier); | ||
|  | |||
| 33 | |||
| 34 | $parser->getGedcom()->addObje($obje); | ||
| 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 'FILE': | ||
| 50 | $obje->setFile(trim($record[2])); | ||
| 51 | break; | ||
| 52 | case 'REFN': | ||
| 53 | $refn = \PhpGedcom\Parser\Refn::parse($parser); | ||
| 54 | $obje->addRefn($refn); | ||
| 55 | break; | ||
| 56 | case 'RIN': | ||
| 57 | $obje->setRin(trim($record[2])); | ||
| 58 | break; | ||
| 59 | |||
| 60 | case 'NOTE': | ||
| 61 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); | ||
| 62 |                     if ($note) { | ||
| 63 | $obje->addNote($note); | ||
| 64 | } | ||
| 65 | break; | ||
| 66 | case 'SOUR': | ||
| 67 | $chan = \PhpGedcom\Parser\Chan::parse($parser); | ||
| 68 | $obje->setChan($chan); | ||
| 69 | break; | ||
| 70 | |||
| 71 | case 'CHAN': | ||
| 72 | $chan = \PhpGedcom\Parser\Chan::parse($parser); | ||
| 73 | $obje->setChan($chan); | ||
| 74 | break; | ||
| 75 | |||
| 76 | default: | ||
| 77 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); | ||
| 78 | } | ||
| 79 | |||
| 80 | $parser->forward(); | ||
| 81 | } | ||
| 82 | |||
| 83 | return $obje; | ||
| 84 | } | ||
| 86 |