| Conditions | 10 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 38 |
| 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 | |||
| 24 | $slgs = new \Gedcom\Record\Fam\Slgs(); |
||
| 25 | |||
| 26 | $parser->forward(); |
||
| 27 | |||
| 28 | while (!$parser->eof()) { |
||
| 29 | $record = $parser->getCurrentLineRecord(); |
||
| 30 | $recordType = strtoupper(trim($record[1])); |
||
| 31 | $currentDepth = (int) $record[0]; |
||
| 32 | |||
| 33 | if ($currentDepth <= $depth) { |
||
| 34 | $parser->back(); |
||
| 35 | break; |
||
| 36 | } |
||
| 37 | |||
| 38 | switch ($recordType) { |
||
| 39 | case 'STAT': |
||
| 40 | $stat = \Gedcom\Parser\Fam\Slgs\Stat::parse($parser); |
||
| 41 | $slgs->setStat($stat); |
||
|
|
|||
| 42 | break; |
||
| 43 | case 'DATE': |
||
| 44 | $slgs->setDate(trim($record[2])); |
||
| 45 | break; |
||
| 46 | case 'PLAC': |
||
| 47 | $slgs->setPlac(trim($record[2])); |
||
| 48 | break; |
||
| 49 | case 'TEMP': |
||
| 50 | $slgs->setTemp(trim($record[2])); |
||
| 51 | break; |
||
| 52 | case 'SOUR': |
||
| 53 | $sour = \Gedcom\Parser\SourRef::parse($parser); |
||
| 54 | $slgs->addSour($sour); |
||
| 55 | break; |
||
| 56 | case 'NOTE': |
||
| 57 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||
| 58 | if ($note) { |
||
| 59 | $slgs->addNote($note); |
||
| 60 | } |
||
| 61 | break; |
||
| 62 | default: |
||
| 63 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||
| 64 | } |
||
| 65 | |||
| 66 | $parser->forward(); |
||
| 67 | } |
||
| 68 | |||
| 69 | return $slgs; |
||
| 70 | } |
||
| 72 |