Note   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 50
dl 0
loc 69
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 67 13
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 Note extends \Gedcom\Parser\Component
18
{
19
    public static function parse(\Gedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord(4);
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
        $note = new \Gedcom\Record\Note();
32
        $note->setId($identifier);
0 ignored issues
show
Bug introduced by
The method setId() does not exist on Gedcom\Record\Note. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

32
        $note->/** @scrutinizer ignore-call */ 
33
               setId($identifier);
Loading history...
33
34
        if (isset($record[3])) {
35
            $note->setNote($record[3]);
0 ignored issues
show
Bug introduced by
The method setNote() does not exist on Gedcom\Record\Note. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

35
            $note->/** @scrutinizer ignore-call */ 
36
                   setNote($record[3]);
Loading history...
36
        }
37
38
        $parser->forward();
39
40
        while (!$parser->eof()) {
41
            $record = $parser->getCurrentLineRecord();
42
            $currentDepth = (int) $record[0];
43
            $recordType = strtoupper(trim($record[1]));
44
45
            if ($currentDepth <= $depth) {
46
                $parser->back();
47
                break;
48
            }
49
50
            switch ($recordType) {
51
                case 'CONT':
52
                    $note->setNote($note->getNote()."\n");
0 ignored issues
show
Bug introduced by
Are you sure $note->getNote() of type Gedcom\Record\Note|mixed|null can be used in concatenation? ( Ignorable by Annotation )

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

52
                    $note->setNote(/** @scrutinizer ignore-type */ $note->getNote()."\n");
Loading history...
Bug introduced by
The method getNote() does not exist on Gedcom\Record\Note. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

52
                    $note->setNote($note->/** @scrutinizer ignore-call */ getNote()."\n");
Loading history...
53
                    if (isset($record[2])) {
54
                        $note->setNote($note->getNote().$record[2]);
55
                    }
56
                    break;
57
                case 'CONC':
58
                    if (isset($record[2])) {
59
                        $note->setNote($note->getNote().$record[2]);
60
                    }
61
                    break;
62
                case 'REFN':
63
                    $refn = \Gedcom\Parser\Refn::parse($parser);
64
                    $note->addRefn($refn);
65
                    break;
66
                case 'RIN':
67
                    $note->setRin(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setRin() does not exist on Gedcom\Record\Note. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

67
                    $note->/** @scrutinizer ignore-call */ 
68
                           setRin(trim($record[2]));
Loading history...
68
                    break;
69
                case 'SOUR':
70
                    $sour = \Gedcom\Parser\SourRef::parse($parser);
71
                    $note->addSour($sour);
72
                    break;
73
                case 'CHAN':
74
                    $chan = \Gedcom\Parser\Chan::parse($parser);
75
                    $note->setChan($chan);
0 ignored issues
show
Bug introduced by
The method setChan() does not exist on Gedcom\Record\Note. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

75
                    $note->/** @scrutinizer ignore-call */ 
76
                           setChan($chan);
Loading history...
76
                    break;
77
                default:
78
                    $parser->logUnhandledRecord(self::class.' @ '.__LINE__);
79
            }
80
81
            $parser->forward();
82
        }
83
        $parser->getGedcom()->addNote($note);
84
85
        return $note;
86
    }
87
}
88