| 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 |
||
| 28 | public static function parse(\PhpGedcom\Parser $parser) |
||
| 29 | { |
||
| 30 | $record = $parser->getCurrentLineRecord(); |
||
| 31 | $depth = (int) $record[0]; |
||
| 32 | if(isset($record[1])){ |
||
| 33 | $identifier = $parser->normalizeIdentifier($record[1]); |
||
| 34 | } |
||
| 35 | else{ |
||
| 36 | $parser->skipToNextLevel($depth); |
||
| 37 | return null; |
||
| 38 | } |
||
| 39 | |||
| 40 | $obje = new \PhpGedcom\Record\Obje(); |
||
| 41 | $obje->setId($identifier); |
||
|
|
|||
| 42 | |||
| 43 | $parser->getGedcom()->addObje($obje); |
||
| 44 | |||
| 45 | $parser->forward(); |
||
| 46 | |||
| 47 | while (!$parser->eof()) { |
||
| 48 | $record = $parser->getCurrentLineRecord(); |
||
| 49 | $currentDepth = (int) $record[0]; |
||
| 50 | $recordType = strtoupper(trim($record[1])); |
||
| 51 | |||
| 52 | if ($currentDepth <= $depth) { |
||
| 53 | $parser->back(); |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | |||
| 57 | switch ($recordType) { |
||
| 58 | case 'FILE': |
||
| 59 | $obje->setFile(trim($record[2])); |
||
| 60 | break; |
||
| 61 | case 'REFN': |
||
| 62 | $refn = \PhpGedcom\Parser\Refn::parse($parser); |
||
| 63 | $obje->addRefn($refn); |
||
| 64 | break; |
||
| 65 | case 'RIN': |
||
| 66 | $obje->setRin(trim($record[2])); |
||
| 67 | break; |
||
| 68 | |||
| 69 | case 'NOTE': |
||
| 70 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); |
||
| 71 | if ($note) { |
||
| 72 | $obje->addNote($note); |
||
| 73 | } |
||
| 74 | break; |
||
| 75 | case 'SOUR': |
||
| 76 | $chan = \PhpGedcom\Parser\Chan::parse($parser); |
||
| 77 | $obje->setChan($chan); |
||
| 78 | break; |
||
| 79 | |||
| 80 | case 'CHAN': |
||
| 81 | $chan = \PhpGedcom\Parser\Chan::parse($parser); |
||
| 82 | $obje->setChan($chan); |
||
| 83 | break; |
||
| 84 | |||
| 85 | default: |
||
| 86 | $parser->logUnhandledRecord(get_class() . ' @ ' . __LINE__); |
||
| 87 | } |
||
| 88 | |||
| 89 | $parser->forward(); |
||
| 90 | } |
||
| 91 | |||
| 92 | return $obje; |
||
| 93 | } |
||
| 95 |