Lds::parse()   C
last analyzed

Complexity

Conditions 12
Paths 3

Size

Total Lines 63
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 63
c 0
b 0
f 0
rs 6.9666
cc 12
nc 3
nop 1

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * php-gedcom.
4
 *
5
 * php-gedcom is a library for parsing, manipulating, importing and exporting
6
 * GEDCOM 5.5 files in PHP 5.3+.
7
 *
8
 * @author          Kristopher Wilson <[email protected]>
9
 * @copyright       Copyright (c) 2010-2013, Kristopher Wilson
10
 * @license         MIT
11
 *
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace Gedcom\Parser\Indi;
16
17
abstract class Lds extends \Gedcom\Parser\Component
18
{
19
    public static function parse(\Gedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
        if (isset($record[1])) {
24
            $className = 'GedcomRecordIndi'.ucfirst(strtolower(trim($record[1])));
25
            $lds = new $className();
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
            switch ($recordType) {
45
                case 'STAT':
46
                    $lds->setStat(trim($record[2]));
47
                    break;
48
                case 'DATE':
49
                    $lds->setDate(trim($record[2]));
50
                    break;
51
                case 'PLAC':
52
                    $lds->setPlac(trim($record[2]));
53
                    break;
54
                case 'TEMP':
55
                    $lds->setTemp(trim($record[2]));
56
                    break;
57
                case 'SOUR':
58
                    $sour = \Gedcom\Parser\SourRef::parse($parser);
59
                    $lds->addSour($sour);
60
                    break;
61
                case 'NOTE':
62
                    $note = \Gedcom\Parser\NoteRef::parse($parser);
63
                    if ($note) {
64
                        $lds->addNote($note);
65
                    }
66
                    break;
67
                default:
68
                    $self = get_called_class();
69
                    $method = 'parse'.$recordType;
70
71
                    if (method_exists($self, $method)) {
72
                        $self::$method($parser, $lds);
73
                    } else {
74
                        $parser->logUnhandledRecord($self.' @ '.__LINE__);
75
                    }
76
            }
77
78
            $parser->forward();
79
        }
80
81
        return $lds;
82
    }
83
}
84