Fams::parse()   B
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 44
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 44
c 0
b 0
f 0
rs 8.8657
cc 6
nc 3
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\Indi;
16
17
class Fams extends \Gedcom\Parser\Component
18
{
19
    public static function parse(\Gedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
24
        if (count($record) < 3) {
0 ignored issues
show
Bug introduced by
It seems like $record can also be of type false; however, parameter $value 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

24
        if (count(/** @scrutinizer ignore-type */ $record) < 3) {
Loading history...
25
            $parser->logSkippedRecord('Missing family information; '.self::class, ' @ '.__LINE__);
0 ignored issues
show
Unused Code introduced by
The call to Gedcom\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

25
            $parser->/** @scrutinizer ignore-call */ 
26
                     logSkippedRecord('Missing family information; '.self::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...
26
            $parser->skipToNextLevel($depth);
27
28
            return null;
29
        }
30
31
        $fams = $parser->normalizeIdentifier($record[2]);
32
33
        $fam = new \Gedcom\Record\Indi\Fams();
34
        $fam->setFams($fams);
0 ignored issues
show
Bug introduced by
The method setFams() does not exist on Gedcom\Record\Indi\Fams. 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

34
        $fam->/** @scrutinizer ignore-call */ 
35
              setFams($fams);
Loading history...
35
36
        $parser->forward();
37
38
        while (!$parser->eof()) {
39
            $record = $parser->getCurrentLineRecord();
40
            $recordType = strtoupper(trim($record[1]));
41
            $currentDepth = (int) $record[0];
42
43
            if ($currentDepth <= $depth) {
44
                $parser->back();
45
                break;
46
            }
47
48
            switch ($recordType) {
49
                case 'NOTE':
50
                    $note = \Gedcom\Parser\NoteRef::parse($parser);
51
                    if ($note) {
52
                        $fam->addNote($note);
53
                    }
54
                    break;
55
                default:
56
                    $parser->logUnhandledRecord(self::class.' @ '.__LINE__);
57
            }
58
59
            $parser->forward();
60
        }
61
62
        return $fam;
63
    }
64
}
65