Attr   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 64
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 17

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 80 17
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 PhpGedcom\Parser\Indi;
16
17
abstract class Attr extends \PhpGedcom\Parser\Component
18
{
19
    public static function parse(\PhpGedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
        if (isset($record[1])) {
24
            $className = '\\PhpGedcom\\Record\\Indi\\'.ucfirst(strtolower(trim($record[1])));
25
            $attr = new $className();
26
27
            $attr->setType(trim($record[1]));
28
        } else {
29
            $parser->skipToNextLevel($depth);
30
31
            return null;
32
        }
33
34
        if (isset($record[2])) {
35
            $attr->setAttr(trim($record[2]));
36
        }
37
38
        $parser->forward();
39
40
        while (!$parser->eof()) {
41
            $record = $parser->getCurrentLineRecord();
42
            $recordType = strtoupper(trim($record[1]));
43
            $currentDepth = (int) $record[0];
44
45
            if ($currentDepth <= $depth) {
46
                $parser->back();
47
                break;
48
            }
49
50
            switch ($recordType) {
51
                case 'TYPE':
52
                    $attr->setType(trim($record[2]));
53
                    break;
54
                case 'DATE':
55
                    $attr->setDate(trim($record[2]));
56
                    break;
57
                case 'PLAC':
58
                    $plac = \PhpGedcom\Parser\Indi\Even\Plac::parse($parser);
59
                    $attr->setPlac($plac);
60
                    break;
61
                case 'ADDR':
62
                    $attr->setAddr(\PhpGedcom\Parser\Addr::parse($parser));
63
                    break;
64
                case 'PHON':
65
                    $phone = \PhpGedcom\Parser\Phon::parse($parser);
66
                    $attr->addPhon($phone);
67
                    break;
68
                case 'CAUS':
69
                    $attr->setCaus(trim($record[2]));
70
                    break;
71
                case 'AGE':
72
                    $attr->setAge(trim($record[2]));
73
                    break;
74
                case 'AGNC':
75
                    $attr->setAgnc(trim($record[2]));
76
                    break;
77
                case 'SOUR':
78
                    $sour = \PhpGedcom\Parser\SourRef::parse($parser);
79
                    $attr->addSour($sour);
80
                    break;
81
                case 'OBJE':
82
                    $obje = \PhpGedcom\Parser\ObjeRef::parse($parser);
83
                    $attr->addObje($obje);
84
                    break;
85
                case 'NOTE':
86
                    $note = \PhpGedcom\Parser\NoteRef::parse($parser);
87
                    if ($note) {
88
                        $attr->addNote($note);
89
                    }
90
                    break;
91
                default:
92
                    $parser->logUnhandledRecord(get_class().' @ '.__LINE__);
93
            }
94
95
            $parser->forward();
96
        }
97
98
        return $attr;
99
    }
100
}
101