Conditions | 17 |
Paths | 3 |
Total Lines | 75 |
Code Lines | 59 |
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 (isset($record[2])) { |
||
24 | $name = new \Gedcom\Record\Indi\Name(); |
||
25 | $name->setName(trim($record[2])); |
||
|
|||
26 | } else { |
||
27 | $parser->skipToNextLevel($depth); |
||
28 | |||
29 | return null; |
||
30 | } |
||
31 | |||
32 | $parser->forward(); |
||
33 | |||
34 | while (!$parser->eof()) { |
||
35 | $record = $parser->getCurrentLineRecord(); |
||
36 | $recordType = strtoupper(trim($record[1])); |
||
37 | $currentDepth = (int) $record[0]; |
||
38 | |||
39 | if ($currentDepth <= $depth) { |
||
40 | $parser->back(); |
||
41 | break; |
||
42 | } |
||
43 | |||
44 | if (!isset($record[2])) { |
||
45 | $record[2] = ''; |
||
46 | } |
||
47 | |||
48 | switch ($recordType) { |
||
49 | case 'TYPE': |
||
50 | $name->setType(trim($record[2])); |
||
51 | break; |
||
52 | case 'NPFX': |
||
53 | $name->setNpfx(trim($record[2])); |
||
54 | break; |
||
55 | case 'GIVN': |
||
56 | $name->setGivn(trim($record[2])); |
||
57 | break; |
||
58 | case 'NICK': |
||
59 | $name->setNick(trim($record[2])); |
||
60 | break; |
||
61 | case 'SPFX': |
||
62 | $name->setSpfx(trim($record[2])); |
||
63 | break; |
||
64 | case 'SURN': |
||
65 | $name->setSurn(trim($record[2])); |
||
66 | break; |
||
67 | case 'NSFX': |
||
68 | $name->setNsfx(trim($record[2])); |
||
69 | break; |
||
70 | case 'SOUR': |
||
71 | $sour = \Gedcom\Parser\SourRef::parse($parser); |
||
72 | $name->addSour($sour); |
||
73 | break; |
||
74 | case 'NOTE': |
||
75 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||
76 | if ($note) { |
||
77 | $name->addNote($note); |
||
78 | } |
||
79 | break; |
||
80 | case 'FONE': |
||
81 | $name->setFone(\Parser\Indi\Name\Fone::parse($parser)); |
||
82 | break; |
||
83 | case 'ROMN': |
||
84 | $name->setRomn(\Parser\Indi\Name\Romn::parse($parser)); |
||
85 | break; |
||
86 | default: |
||
87 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||
88 | } |
||
89 | |||
90 | $parser->forward(); |
||
91 | } |
||
92 | |||
93 | return $name; |
||
94 | } |
||
96 |