| Conditions | 23 |
| Paths | 17 |
| Total Lines | 101 |
| Code Lines | 78 |
| 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 |
||
| 29 | public static function parse(\PhpGedcom\Parser $parser) { |
||
| 30 | $record = $parser->getCurrentLineRecord(); |
||
| 31 | $depth = (int) $record[0]; |
||
| 32 | if (empty($record[1])) { |
||
| 33 | $parser->skipToNextLevel($depth); |
||
| 34 | return null; |
||
| 35 | } |
||
| 36 | |||
| 37 | $even = null; |
||
| 38 | |||
| 39 | if (strtoupper(trim($record[1])) != 'EVEN') { |
||
| 40 | $className = '\\PhpGedcom\\Record\\Indi\\' . ucfirst(strtolower(trim($record[1]))); |
||
| 41 | $even = new $className(); |
||
| 42 | } else { |
||
| 43 | $even = new \PhpGedcom\Record\Indi\Even(); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (isset($record[1]) && strtoupper(trim($record[1])) != 'EVEN') { |
||
| 47 | $even->setType(trim($record[1])); |
||
| 48 | } |
||
| 49 | |||
| 50 | // ensures we capture any data following the EVEN type |
||
| 51 | if (isset($record[2]) && !empty($record[2])) { |
||
| 52 | $even->setAttr(trim($record[2])); |
||
|
|
|||
| 53 | } |
||
| 54 | |||
| 55 | $parser->forward(); |
||
| 56 | |||
| 57 | while (!$parser->eof()) { |
||
| 58 | $record = $parser->getCurrentLineRecord(); |
||
| 59 | $recordType = strtoupper(trim($record[1])); |
||
| 60 | $currentDepth = (int) $record[0]; |
||
| 61 | |||
| 62 | if ($currentDepth <= $depth) { |
||
| 63 | $parser->back(); |
||
| 64 | break; |
||
| 65 | } |
||
| 66 | |||
| 67 | switch ($recordType) { |
||
| 68 | case 'TYPE': |
||
| 69 | $even->setType(trim($record[2])); |
||
| 70 | break; |
||
| 71 | case 'DATE': |
||
| 72 | $dat = \PhpGedcom\Parser\Date::parse($parser); |
||
| 73 | $even->setDate($dat); |
||
| 74 | //$even->setDate(trim($record[2])) |
||
| 75 | break; |
||
| 76 | case 'PLAC': |
||
| 77 | $plac = \PhpGedcom\Parser\Plac::parse($parser); |
||
| 78 | $even->setPlac($plac); |
||
| 79 | break; |
||
| 80 | case 'ADDR': |
||
| 81 | $even->setAddr(\PhpGedcom\Parser\Addr::parse($parser)); |
||
| 82 | break; |
||
| 83 | case 'PHON': |
||
| 84 | $phone = \PhpGedcom\Parser\Phon::parse($parser); |
||
| 85 | $even->addPhone($phone); |
||
| 86 | break; |
||
| 87 | case 'CAUS': |
||
| 88 | $even->setCaus(trim($record[2])); |
||
| 89 | break; |
||
| 90 | case 'AGE': |
||
| 91 | $even->setAge(trim($record[2])); |
||
| 92 | break; |
||
| 93 | case 'AGNC': |
||
| 94 | $even->setAgnc(trim($record[2])); |
||
| 95 | break; |
||
| 96 | case 'SOUR': |
||
| 97 | $sour = \PhpGedcom\Parser\SourRef::parse($parser); |
||
| 98 | $even->addSour($sour); |
||
| 99 | break; |
||
| 100 | case 'OBJE': |
||
| 101 | $obje = \PhpGedcom\Parser\ObjeRef::parse($parser); |
||
| 102 | $even->addObje($obje); |
||
| 103 | break; |
||
| 104 | case 'NOTE': |
||
| 105 | $note = \PhpGedcom\Parser\NoteRef::parse($parser); |
||
| 106 | if ($note) { |
||
| 107 | $even->addNote($note); |
||
| 108 | } |
||
| 109 | break; |
||
| 110 | case 'CHAN': |
||
| 111 | $change = Chan::parse($parser); |
||
| 112 | $even->setChan($change); |
||
| 113 | break; |
||
| 114 | default: |
||
| 115 | $self = get_called_class(); |
||
| 116 | $method = 'parse' . $recordType; |
||
| 117 | |||
| 118 | if (method_exists($self, $method)) { |
||
| 119 | $self::$method($parser, $even); |
||
| 120 | } else { |
||
| 121 | $parser->logUnhandledRecord($self . ' @ ' . __LINE__); |
||
| 122 | $parser->skipToNextLevel($currentDepth); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $parser->forward(); |
||
| 127 | } |
||
| 128 | |||
| 129 | return $even; |
||
| 130 | } |
||
| 132 |