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