Chan   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 30
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 43 7
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;
16
17
class Chan extends \Gedcom\Parser\Component
18
{
19
    public static function parse(\Gedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
24
        $parser->forward();
25
26
        $chan = new \Gedcom\Record\Chan();
27
28
        while (!$parser->eof()) {
29
            $record = $parser->getCurrentLineRecord();
30
            $recordType = trim($record[1]);
31
            $currentDepth = (int) $record[0];
32
33
            if ($currentDepth <= $depth) {
34
                $parser->back();
35
                break;
36
            }
37
38
            switch ($recordType) {
39
                case 'DATE':
40
                    $chan->setDate(trim($record[2]));
41
                    break;
42
                case 'TIME':
43
                    $chan->setTime(trim($record[2]));
44
                    break;
45
                case 'NOTE':
46
                    $note = \Gedcom\Parser\NoteRef::parse($parser);
47
                    if ($note) {
48
                        $chan->addNote($note);
49
                    }
50
                    break;
51
                default:
52
                    $parser->logUnhandledRecord(self::class.' @ '.__LINE__);
53
            }
54
55
            $parser->forward();
56
        }
57
58
        $date = $chan->getYear().'-'.$chan->getMonth().'-'.$chan->getDay();
59
        $chan->setDatetime($date);
60
61
        return $chan;
62
    }
63
}
64