| Conditions | 10 |
| Paths | 3 |
| Total Lines | 56 |
| Code Lines | 41 |
| 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[2])) { |
||
| 24 | $_plac = trim($record[2]); |
||
| 25 | } else { |
||
| 26 | $parser->skipToNextLevel($depth); |
||
| 27 | |||
| 28 | return null; |
||
| 29 | } |
||
| 30 | |||
| 31 | $plac = new \PhpGedcom\Record\Plac(); |
||
| 32 | $plac->setPlac($_plac); |
||
|
|
|||
| 33 | |||
| 34 | $parser->forward(); |
||
| 35 | |||
| 36 | while (!$parser->eof()) { |
||
| 37 | $record = $parser->getCurrentLineRecord(); |
||
| 38 | $currentDepth = (int) $record[0]; |
||
| 39 | $recordType = strtoupper(trim($record[1])); |
||
| 40 | |||
| 41 | if ($currentDepth <= $depth) { |
||
| 42 | $parser->back(); |
||
| 43 | break; |
||
| 44 | } |
||
| 45 | |||
| 46 | switch ($recordType) { |
||
| 47 | case 'FORM': |
||
| 48 | $plac->setForm(trim($record[2])); |
||
| 49 | break; |
||
| 50 | case 'FONE': |
||
| 51 | $fone = \PhpGedcom\Parser\Plac\Fone::parse($parser); |
||
| 52 | $plac->setFone($fone); |
||
| 53 | break; |
||
| 54 | case 'ROMN': |
||
| 55 | $romn = \PhpGedcom\Parser\Plac\Romn::parse($parser); |
||
| 56 | $plac->setRomn($romn); |
||
| 57 | break; |
||
| 58 | case 'NOTE': |
||
| 59 | if ($note = \PhpGedcom\Parser\NoteRef::parse($parser)) { |
||
| 60 | $plac->addNote($note); |
||
| 61 | } |
||
| 62 | break; |
||
| 63 | case 'MAP': |
||
| 64 | $map = \PhpGedcom\Parser\Plac\Map::parse($parser); |
||
| 65 | $plac->setMap($map); |
||
| 66 | break; |
||
| 67 | default: |
||
| 68 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 69 | } |
||
| 70 | |||
| 71 | $parser->forward(); |
||
| 72 | } |
||
| 73 | |||
| 74 | return $plac; |
||
| 75 | } |
||
| 77 |