Romn::parse()   C
last analyzed

Complexity

Conditions 12
Paths 3

Size

Total Lines 59
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 59
c 0
b 0
f 0
rs 6.9666
cc 12
nc 3
nop 1

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
 * @license         MIT
11
 *
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace Gedcom\Parser\Indi\Name;
16
17
class Romn extends \Gedcom\Parser\Component
18
{
19
    public static function parse(\Gedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
        if (isset($record[2])) {
24
            $romn = new \Gedcom\Record\Indi\Name\Romn();
25
            $romn->setRomn(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setRomn() does not exist on Gedcom\Record\Indi\Name\Romn. 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

25
            $romn->/** @scrutinizer ignore-call */ 
26
                   setRomn(trim($record[2]));
Loading history...
26
        } else {
27
            $parser->skipToNextLevel($depth);
28
29
            return null;
30
        }
31
32
        $parser->forward();
33
34
        while (!$parser->eof()) {
35
            $record = $parser->getCurrentLineRecord();
36
            $recordType = strtoupper(trim($record[1]));
37
            $currentDepth = (int) $record[0];
38
39
            if ($currentDepth <= $depth) {
40
                $parser->back();
41
                break;
42
            }
43
44
            if (!isset($record[2])) {
45
                $record[2] = '';
46
            }
47
48
            switch ($recordType) {
49
                case 'TYPE':
50
                    $romn->setRomn(trim($record[2]));
51
                    break;
52
                case 'NPFX':
53
                    $romn->setNpfx(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setNpfx() does not exist on Gedcom\Record\Indi\Name\Romn. 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

53
                    $romn->/** @scrutinizer ignore-call */ 
54
                           setNpfx(trim($record[2]));
Loading history...
54
                    break;
55
                case 'GIVN':
56
                    $romn->setGivn(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setGivn() does not exist on Gedcom\Record\Indi\Name\Romn. 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

56
                    $romn->/** @scrutinizer ignore-call */ 
57
                           setGivn(trim($record[2]));
Loading history...
57
                    break;
58
                case 'NICK':
59
                    $romn->setNick(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setNick() does not exist on Gedcom\Record\Indi\Name\Romn. 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
                    $romn->/** @scrutinizer ignore-call */ 
60
                           setNick(trim($record[2]));
Loading history...
60
                    break;
61
                case 'SPFX':
62
                    $romn->setSpfx(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setSpfx() does not exist on Gedcom\Record\Indi\Name\Romn. 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

62
                    $romn->/** @scrutinizer ignore-call */ 
63
                           setSpfx(trim($record[2]));
Loading history...
63
                    break;
64
                case 'SURN':
65
                    $romn->setSurn(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setSurn() does not exist on Gedcom\Record\Indi\Name\Romn. 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

65
                    $romn->/** @scrutinizer ignore-call */ 
66
                           setSurn(trim($record[2]));
Loading history...
66
                    break;
67
                case 'NSFX':
68
                    $romn->setNsfx(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setNsfx() does not exist on Gedcom\Record\Indi\Name\Romn. 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

68
                    $romn->/** @scrutinizer ignore-call */ 
69
                           setNsfx(trim($record[2]));
Loading history...
69
                    break;
70
                default:
71
                    $parser->logUnhandledRecord(self::class.' @ '.__LINE__);
72
            }
73
74
            $parser->forward();
75
        }
76
77
        return $romn;
78
    }
79
}
80