Sour   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 65
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;
16
17
class Sour 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
        $sour = new \PhpGedcom\Record\Sour();
32
        $sour->setSour($identifier);
33
34
        $parser->getGedcom()->addSour($sour);
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 'DATA':
50
                    $sour->setData(\PhpGedcom\Parser\Sour\Data::parse($parser));
0 ignored issues
show
Bug introduced by
PhpGedcom\Parser\Sour\Data::parse($parser) of type PhpGedcom\Record\Sour\Data is incompatible with the type string expected by parameter $data of PhpGedcom\Record\Sour::setData(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
                    $sour->setData(/** @scrutinizer ignore-type */ \PhpGedcom\Parser\Sour\Data::parse($parser));
Loading history...
51
                    break;
52
                case 'AUTH':
53
                    $sour->setAuth($parser->parseMultilineRecord());
54
                    break;
55
                case 'TITL':
56
                    $sour->setTitl($parser->parseMultilineRecord());
57
                    break;
58
                case 'ABBR':
59
                    $sour->setAbbr(trim($record[2]));
60
                    break;
61
                case 'PUBL':
62
                    $sour->setPubl($parser->parseMultilineRecord());
63
                    break;
64
                case 'TEXT':
65
                    $sour->setText($parser->parseMultilineRecord());
66
                    break;
67
                case 'REPO':
68
                    $sour->setRepo(\PhpGedcom\Parser\Sour\Repo::parse($parser));
0 ignored issues
show
Bug introduced by
PhpGedcom\Parser\Sour\Repo::parse($parser) of type PhpGedcom\Record\Sour\Repo is incompatible with the type PhpGedcom\Record\Repo expected by parameter $repo of PhpGedcom\Record\Sour::setRepo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
                    $sour->setRepo(/** @scrutinizer ignore-type */ \PhpGedcom\Parser\Sour\Repo::parse($parser));
Loading history...
69
                    break;
70
                case 'REFN':
71
                    $refn = \PhpGedcom\Parser\Refn::parse($parser);
72
                    $sour->addRefn($refn);
73
                    break;
74
                case 'RIN':
75
                    $sour->setRin(trim($record[2]));
76
                    break;
77
                case 'CHAN':
78
                    $chan = \PhpGedcom\Parser\Chan::parse($parser);
79
                    $sour->setChan($chan);
80
                    break;
81
                case 'NOTE':
82
                    $note = \PhpGedcom\Parser\NoteRef::parse($parser);
83
                    if ($note) {
84
                        $sour->addNote($note);
85
                    }
86
                    break;
87
                case 'OBJE':
88
                    $obje = \PhpGedcom\Parser\ObjeRef::parse($parser);
89
                    $sour->addObje($obje);
90
                    break;
91
                default:
92
                    $parser->logUnhandledRecord(get_class().' @ '.__LINE__);
93
            }
94
95
            $parser->forward();
96
        }
97
98
        return $sour;
99
    }
100
}
101