Addr::parse()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 38
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 38
c 0
b 0
f 0
rs 8.6026
cc 7
nc 4
nop 1
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 Addr extends \Gedcom\Parser\Component
18
{
19
    public static function parse(\Gedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
        $line = isset($record[2]) ? trim($record[2]) : '';
24
25
        $addr = new \Gedcom\Record\Addr();
26
        $addr->setAddr($line);
27
        $parser->forward();
28
29
        while (!$parser->eof()) {
30
            $record = $parser->getCurrentLineRecord();
31
            $recordType = strtolower(trim($record[1]));
32
            $currentDepth = (int) $record[0];
33
34
            if ($currentDepth <= $depth) {
35
                $parser->back();
36
                break;
37
            }
38
39
            if ($addr->hasAttribute($recordType)) {
40
                $addr->{'set'.$recordType}(trim($record[2]));
41
            } else {
42
                if ($recordType == 'cont') {
43
                    // FIXME: Can have CONT on multiple attributes
44
                    $addr->setAddr($addr->getAddr()."\n");
45
                    if (isset($record[2])) {
46
                        $addr->setAddr($addr->getAddr().trim($record[2]));
47
                    }
48
                } else {
49
                    $parser->logUnhandledRecord(self::class.' @ '.__LINE__);
50
                }
51
            }
52
53
            $parser->forward();
54
        }
55
56
        return $addr;
57
    }
58
}
59