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