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

Obje::parse()   B

Complexity

Conditions 11
Paths 3

Size

Total Lines 65
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 46
nc 3
nop 1
dl 0
loc 65
rs 7.3166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Obje 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[1])){
33
          $identifier = $parser->normalizeIdentifier($record[1]);
34
        }
35
        else{
36
           $parser->skipToNextLevel($depth);
37
           return null;
38
        }
39
40
        $obje = new \PhpGedcom\Record\Obje();
41
        $obje->setId($identifier);
0 ignored issues
show
Bug introduced by
The method setId() does not exist on PhpGedcom\Record\Obje. 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

41
        $obje->/** @scrutinizer ignore-call */ 
42
               setId($identifier);
Loading history...
42
43
        $parser->getGedcom()->addObje($obje);
44
45
        $parser->forward();
46
47
        while (!$parser->eof()) {
48
            $record = $parser->getCurrentLineRecord();
49
            $currentDepth = (int) $record[0];
50
            $recordType = strtoupper(trim($record[1]));
51
52
            if ($currentDepth <= $depth) {
53
                $parser->back();
54
                break;
55
            }
56
57
            switch ($recordType) {
58
                case 'FILE':
59
                    $obje->setFile(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setFile() does not exist on PhpGedcom\Record\Obje. 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

59
                    $obje->/** @scrutinizer ignore-call */ 
60
                           setFile(trim($record[2]));
Loading history...
60
                    break;
61
                case 'REFN':
62
                    $refn = \PhpGedcom\Parser\Refn::parse($parser);
63
                    $obje->addRefn($refn);
64
                    break;
65
                case 'RIN':
66
                    $obje->setRin(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setRin() does not exist on PhpGedcom\Record\Obje. 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

66
                    $obje->/** @scrutinizer ignore-call */ 
67
                           setRin(trim($record[2]));
Loading history...
67
                    break;
68
69
                case 'NOTE':
70
                    $note = \PhpGedcom\Parser\NoteRef::parse($parser);
71
                    if ($note) {
72
                        $obje->addNote($note);
73
                    }
74
                    break;
75
                case 'SOUR':
76
                    $chan = \PhpGedcom\Parser\Chan::parse($parser);
77
                    $obje->setChan($chan);
0 ignored issues
show
Bug introduced by
The method setChan() does not exist on PhpGedcom\Record\Obje. 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

77
                    $obje->/** @scrutinizer ignore-call */ 
78
                           setChan($chan);
Loading history...
78
                    break;
79
    
80
                case 'CHAN':
81
                    $chan = \PhpGedcom\Parser\Chan::parse($parser);
82
                    $obje->setChan($chan);
83
                    break;
84
85
                default:
86
                    $parser->logUnhandledRecord(get_class() . ' @ ' . __LINE__);
87
            }
88
89
            $parser->forward();
90
        }
91
92
        return $obje;
93
    }
94
}
95