Conditions | 13 |
Paths | 5 |
Total Lines | 67 |
Code Lines | 49 |
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(4); |
||
22 | $depth = (int) $record[0]; |
||
23 | if (isset($record[1])) { |
||
24 | $identifier = $parser->normalizeIdentifier($record[1]); |
||
25 | } else { |
||
26 | $parser->skipToNextLevel($depth); |
||
27 | |||
28 | return null; |
||
29 | } |
||
30 | |||
31 | $note = new \Gedcom\Record\Note(); |
||
32 | $note->setId($identifier); |
||
|
|||
33 | |||
34 | if (isset($record[3])) { |
||
35 | $note->setNote($record[3]); |
||
36 | } |
||
37 | |||
38 | $parser->forward(); |
||
39 | |||
40 | while (!$parser->eof()) { |
||
41 | $record = $parser->getCurrentLineRecord(); |
||
42 | $currentDepth = (int) $record[0]; |
||
43 | $recordType = strtoupper(trim($record[1])); |
||
44 | |||
45 | if ($currentDepth <= $depth) { |
||
46 | $parser->back(); |
||
47 | break; |
||
48 | } |
||
49 | |||
50 | switch ($recordType) { |
||
51 | case 'CONT': |
||
52 | $note->setNote($note->getNote()."\n"); |
||
53 | if (isset($record[2])) { |
||
54 | $note->setNote($note->getNote().$record[2]); |
||
55 | } |
||
56 | break; |
||
57 | case 'CONC': |
||
58 | if (isset($record[2])) { |
||
59 | $note->setNote($note->getNote().$record[2]); |
||
60 | } |
||
61 | break; |
||
62 | case 'REFN': |
||
63 | $refn = \Gedcom\Parser\Refn::parse($parser); |
||
64 | $note->addRefn($refn); |
||
65 | break; |
||
66 | case 'RIN': |
||
67 | $note->setRin(trim($record[2])); |
||
68 | break; |
||
69 | case 'SOUR': |
||
70 | $sour = \Gedcom\Parser\SourRef::parse($parser); |
||
71 | $note->addSour($sour); |
||
72 | break; |
||
73 | case 'CHAN': |
||
74 | $chan = \Gedcom\Parser\Chan::parse($parser); |
||
75 | $note->setChan($chan); |
||
76 | break; |
||
77 | default: |
||
78 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||
79 | } |
||
80 | |||
81 | $parser->forward(); |
||
82 | } |
||
83 | $parser->getGedcom()->addNote($note); |
||
84 | |||
85 | return $note; |
||
86 | } |
||
88 |