| Conditions | 13 |
| Paths | 3 |
| Total Lines | 62 |
| Code Lines | 47 |
| 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(\Gedcom\Parser $parser) |
||
| 20 | { |
||
| 21 | $record = $parser->getCurrentLineRecord(); |
||
| 22 | $depth = (int) $record[0]; |
||
| 23 | if (isset($record[2])) { |
||
| 24 | $sour = new \Gedcom\Record\SourRef(); |
||
| 25 | $sour->setSour($parser->normalizeIdentifier($record[2])); |
||
| 26 | } else { |
||
| 27 | $parser->skipToNextLevel($depth); |
||
| 28 | |||
| 29 | return null; |
||
| 30 | } |
||
| 31 | |||
| 32 | $parser->forward(); |
||
| 33 | |||
| 34 | while (!$parser->eof()) { |
||
| 35 | $record = $parser->getCurrentLineRecord(); |
||
| 36 | $recordType = strtoupper(trim($record[1])); |
||
| 37 | $currentDepth = (int) $record[0]; |
||
| 38 | |||
| 39 | if ($currentDepth <= $depth) { |
||
| 40 | $parser->back(); |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | switch ($recordType) { |
||
| 45 | case 'PAGE': |
||
| 46 | $sour->setPage(trim($record[2])); |
||
|
|
|||
| 47 | break; |
||
| 48 | case 'EVEN': |
||
| 49 | $even = \Gedcom\Parser\SourRef\Even::parse($parser); |
||
| 50 | $sour->setEven($even); |
||
| 51 | break; |
||
| 52 | case 'DATA': |
||
| 53 | $sour->setData(\Gedcom\Parser\SourRef\Data::parse($parser)); |
||
| 54 | break; |
||
| 55 | case 'TEXT': |
||
| 56 | $sour->setText($parser->parseMultiLineRecord()); |
||
| 57 | break; |
||
| 58 | case 'OBJE': |
||
| 59 | $obje = \Gedcom\Parser\ObjeRef::parse($parser); |
||
| 60 | if ($obje) { |
||
| 61 | $sour->addNote($obje); |
||
| 62 | } |
||
| 63 | break; |
||
| 64 | case 'NOTE': |
||
| 65 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||
| 66 | if ($note) { |
||
| 67 | $sour->addNote($note); |
||
| 68 | } |
||
| 69 | break; |
||
| 70 | case 'QUAY': |
||
| 71 | $sour->setQuay(trim($record[2])); |
||
| 72 | break; |
||
| 73 | default: |
||
| 74 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||
| 75 | } |
||
| 76 | |||
| 77 | $parser->forward(); |
||
| 78 | } |
||
| 79 | |||
| 80 | return $sour; |
||
| 81 | } |
||
| 83 |