Conditions | 12 |
Paths | 3 |
Total Lines | 57 |
Code Lines | 43 |
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(\PhpGedcom\Parser $parser) |
||
20 | { |
||
21 | $record = $parser->getCurrentLineRecord(); |
||
22 | $depth = (int) $record[0]; |
||
23 | if (isset($record[2])) { |
||
24 | $fone = new \PhpGedcom\Record\Indi\Name\Fone(); |
||
25 | $fone->setFone(trim($record[2])); |
||
|
|||
26 | } else { |
||
27 | return null; |
||
28 | } |
||
29 | |||
30 | $parser->forward(); |
||
31 | |||
32 | while (!$parser->eof()) { |
||
33 | $record = $parser->getCurrentLineRecord(); |
||
34 | $recordType = strtoupper(trim($record[1])); |
||
35 | $currentDepth = (int) $record[0]; |
||
36 | |||
37 | if ($currentDepth <= $depth) { |
||
38 | $parser->back(); |
||
39 | break; |
||
40 | } |
||
41 | |||
42 | if (!isset($record[2])) { |
||
43 | $record[2] = ''; |
||
44 | } |
||
45 | |||
46 | switch ($recordType) { |
||
47 | case 'TYPE': |
||
48 | $fone->setType(trim($record[2])); |
||
49 | break; |
||
50 | case 'NPFX': |
||
51 | $fone->setNpfx(trim($record[2])); |
||
52 | break; |
||
53 | case 'GIVN': |
||
54 | $fone->setGivn(trim($record[2])); |
||
55 | break; |
||
56 | case 'NICK': |
||
57 | $fone->setNick(trim($record[2])); |
||
58 | break; |
||
59 | case 'SPFX': |
||
60 | $fone->setSpfx(trim($record[2])); |
||
61 | break; |
||
62 | case 'SURN': |
||
63 | $fone->setSurn(trim($record[2])); |
||
64 | break; |
||
65 | case 'NSFX': |
||
66 | $fone->setNsfx(trim($record[2])); |
||
67 | break; |
||
68 | default: |
||
69 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
70 | } |
||
71 | |||
72 | $parser->forward(); |
||
73 | } |
||
74 | |||
75 | return $fone; |
||
76 | } |
||
78 |