| Conditions | 17 |
| Paths | 3 |
| Total Lines | 81 |
| Code Lines | 66 |
| 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 |
||
| 24 | public static function parse(\PhpGedcom\Parser $parser) |
||
| 25 | { |
||
| 26 | $record = $parser->getCurrentLineRecord(); |
||
| 27 | $depth = (int) $record[0]; |
||
| 28 | if (isset($record[1])) { |
||
| 29 | $identifier = $parser->normalizeIdentifier($record[1]); |
||
|
|
|||
| 30 | } else { |
||
| 31 | $parser->skipToNextLevel($depth); |
||
| 32 | |||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | $head = new \PhpGedcom\Record\Head(); |
||
| 37 | |||
| 38 | $parser->getGedcom()->setHead($head); |
||
| 39 | |||
| 40 | $parser->forward(); |
||
| 41 | |||
| 42 | while (!$parser->eof()) { |
||
| 43 | $record = $parser->getCurrentLineRecord(); |
||
| 44 | $currentDepth = (int) $record[0]; |
||
| 45 | $recordType = strtoupper(trim($record[1])); |
||
| 46 | |||
| 47 | if ($currentDepth <= $depth) { |
||
| 48 | $parser->back(); |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | |||
| 52 | switch ($recordType) { |
||
| 53 | case 'SOUR': |
||
| 54 | $sour = \PhpGedcom\Parser\Head\Sour::parse($parser); |
||
| 55 | $head->setSour($sour); |
||
| 56 | break; |
||
| 57 | case 'DEST': |
||
| 58 | $head->setDest(trim($record[2])); |
||
| 59 | break; |
||
| 60 | case 'SUBM': |
||
| 61 | $head->setSubm($parser->normalizeIdentifier($record[2])); |
||
| 62 | break; |
||
| 63 | case 'SUBN': |
||
| 64 | $head->setSubn($parser->normalizeIdentifier($record[2])); |
||
| 65 | break; |
||
| 66 | case 'DEST': |
||
| 67 | $head->setDest(trim($record[2])); |
||
| 68 | break; |
||
| 69 | case 'FILE': |
||
| 70 | $head->setFile(trim($record[2])); |
||
| 71 | break; |
||
| 72 | case 'COPR': |
||
| 73 | $head->setCopr(trim($record[2])); |
||
| 74 | break; |
||
| 75 | case 'LANG': |
||
| 76 | $head->setLang(trim($record[2])); |
||
| 77 | break; |
||
| 78 | case 'DATE': |
||
| 79 | $date = \PhpGedcom\Parser\Head\Date::parse($parser); |
||
| 80 | $head->setDate($date); |
||
| 81 | break; |
||
| 82 | case 'GEDC': |
||
| 83 | $gedc = \PhpGedcom\Parser\Head\Gedc::parse($parser); |
||
| 84 | $head->setGedc($gedc); |
||
| 85 | break; |
||
| 86 | case 'CHAR': |
||
| 87 | $char = \PhpGedcom\Parser\Head\Char::parse($parser); |
||
| 88 | $head->setChar($char); |
||
| 89 | break; |
||
| 90 | case 'PLAC': |
||
| 91 | $plac = \PhpGedcom\Parser\Head\Plac::parse($parser); |
||
| 92 | $head->setPlac($plac); |
||
| 93 | break; |
||
| 94 | case 'NOTE': |
||
| 95 | $head->setNote($parser->parseMultiLineRecord()); |
||
| 96 | break; |
||
| 97 | default: |
||
| 98 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 99 | } |
||
| 100 | |||
| 101 | $parser->forward(); |
||
| 102 | } |
||
| 103 | |||
| 104 | return $head; |
||
| 105 | } |
||
| 107 |