Passed
Branch master (6a7148)
by Curtis
01:48
created

Phon::parse()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 35
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 3
nop 1
dl 0
loc 35
rs 9.584
c 0
b 0
f 0
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
 * @package         php-gedcom
11
 * @license         MIT
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace PhpGedcom\Parser;
16
17
/**
18
 *
19
 *
20
 */
21
class Phon extends \PhpGedcom\Parser\Component
22
{
23
24
    /**
25
     *
26
     *
27
     */
28
    public static function parse(\PhpGedcom\Parser $parser)
29
    {
30
        $record = $parser->getCurrentLineRecord();
31
        $depth = (int)$record[0];
32
        if(isset($record[2])){
33
          $phone = new \PhpGedcom\Record\Phon();
34
          $phone->setPhon(trim($record[2]));
35
        }
36
        else{
37
           $parser->skipToNextLevel($depth);
38
           return null;
39
        }
40
41
42
        $parser->forward();
43
44
        while (!$parser->eof()) {
45
            $record = $parser->getCurrentLineRecord();
46
            $recordType = strtoupper(trim($record[1]));
47
            $currentDepth = (int)$record[0];
48
49
            if ($currentDepth <= $depth) {
50
                $parser->back();
51
                break;
52
            }
53
54
            switch ($recordType) {
55
                default:
56
                    $parser->logUnhandledRecord(get_class() . ' @ ' . __LINE__);
57
            }
58
59
            $parser->forward();
60
        }
61
62
        return $phone;
63
    }
64
}
65