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

NoteRef   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 47 6
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
class NoteRef extends \PhpGedcom\Parser\Component
21
{
22
    /**
23
     *
24
     */
25
    public static function parse(\PhpGedcom\Parser $parser)
26
    {
27
        $record = $parser->getCurrentLineRecord();
28
        $depth = (int)$record[0];
29
30
        $note = new \PhpGedcom\Record\NoteRef();
31
32
        if (count($record) < 3) {
0 ignored issues
show
Bug introduced by
It seems like $record can also be of type false; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

32
        if (count(/** @scrutinizer ignore-type */ $record) < 3) {
Loading history...
33
            $parser->logSkippedRecord('Missing note information; ' . get_class(), ' @ ' . __LINE__);
0 ignored issues
show
Unused Code introduced by
The call to PhpGedcom\Parser::logSkippedRecord() has too many arguments starting with ' @ ' . __LINE__. ( Ignorable by Annotation )

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

33
            $parser->/** @scrutinizer ignore-call */ 
34
                     logSkippedRecord('Missing note information; ' . get_class(), ' @ ' . __LINE__);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
34
            $parser->skipToNextLevel($depth);
35
            return null;
36
        }
37
38
        if (preg_match('/^@(.*)@$/', trim($record[2]))) {
39
            $note->setIsReference(true);
40
            $note->setNote($parser->normalizeIdentifier($record[2]));
0 ignored issues
show
Bug introduced by
The method setNote() does not exist on PhpGedcom\Record\NoteRef. 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

40
            $note->/** @scrutinizer ignore-call */ 
41
                   setNote($parser->normalizeIdentifier($record[2]));
Loading history...
41
        } else {
42
            $before = $parser->getCurrentLine();
0 ignored issues
show
Unused Code introduced by
The assignment to $before is dead and can be removed.
Loading history...
43
            $note->setIsReference(false);
44
            $note->setNote($parser->parseMultiLineRecord());
45
        }
46
47
        $parser->forward();
48
49
        while (!$parser->eof()) {
50
            $record = $parser->getCurrentLineRecord();
51
            $recordType = strtoupper(trim($record[1]));
52
            $currentDepth = (int)$record[0];
53
54
            if ($currentDepth <= $depth) {
55
                $parser->back();
56
                break;
57
            }
58
59
            switch ($recordType) {
60
                case 'SOUR':
61
                    $sour = \PhpGedcom\Parser\SourRef::parse($parser);
62
                    $note->addSour($sour);
63
                    break;
64
                default:
65
                    $parser->logUnhandledRecord(get_class() . ' @ ' . __LINE__);
66
            }
67
68
            $parser->forward();
69
        }
70
71
        return $note;
72
    }
73
}
74