Subn   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 14

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 69 14
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;
16
17
class Subn 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
            $identifier = $parser->normalizeIdentifier($record[1]);
25
        } else {
26
            $parser->skipToNextLevel($depth);
27
28
            return null;
29
        }
30
31
        $subn = new \PhpGedcom\Record\Subn();
32
        $subn->setSubn($identifier);
33
34
        $parser->getGedcom()->setSubn($subn);
35
36
        $parser->forward();
37
38
        while (!$parser->eof()) {
39
            $record = $parser->getCurrentLineRecord();
40
            $currentDepth = (int) $record[0];
41
            $recordType = strtoupper(trim($record[1]));
42
43
            if ($currentDepth <= $depth) {
44
                $parser->back();
45
                break;
46
            }
47
48
            switch ($recordType) {
49
                case 'SUBM':
50
                    $subn->setSubm($parser->normalizeIdentifier($record[2]));
51
                    break;
52
                case 'FAMF':
53
                    $subn->setFamf(trim($record[2]));
54
                    break;
55
                case 'TEMP':
56
                    $subn->setTemp(trim($record[2]));
57
                    break;
58
                case 'ANCE':
59
                    $subn->setAnce(trim($record[2]));
60
                    break;
61
                case 'DESC':
62
                    $subn->setDesc(trim($record[2]));
63
                    break;
64
                case 'ORDI':
65
                    $subn->setOrdi(trim($record[2]));
66
                    break;
67
                case 'RIN':
68
                    $subn->setRin(trim($record[2]));
69
                    break;
70
                case 'NOTE':
71
                    $note = \PhpGedcom\Parser\NoteRef::parse($parser);
72
                    if ($note) {
73
                        $subn->addNote($note);
74
                    }
75
                    break;
76
                case 'CHAN':
77
                    $chan = \PhpGedcom\Parser\Chan::parse($parser);
78
                    $subn->setChan($chan);
79
                    break;
80
                default:
81
                    $parser->logUnhandledRecord(get_class().' @ '.__LINE__);
82
            }
83
84
            $parser->forward();
85
        }
86
87
        return $subn;
88
    }
89
}
90