Fone::parse()   C
last analyzed

Complexity

Conditions 12
Paths 3

Size

Total Lines 57
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 43
nc 3
nop 1
dl 0
loc 57
rs 6.9666
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
 * @license         MIT
11
 *
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace PhpGedcom\Parser\Indi\Name;
16
17
class Fone extends \PhpGedcom\Parser\Component
18
{
19
    public static function parse(\PhpGedcom\Parser $parser)
20
    {
21
        $record = $parser->getCurrentLineRecord();
22
        $depth = (int) $record[0];
23
        if (isset($record[2])) {
24
            $fone = new \PhpGedcom\Record\Indi\Name\Fone();
25
            $fone->setFone(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setFone() does not exist on PhpGedcom\Record\Indi\Name\Fone. 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
            $fone->/** @scrutinizer ignore-call */ 
26
                   setFone(trim($record[2]));
Loading history...
26
        } else {
27
            return null;
28
        }
29
30
        $parser->forward();
31
32
        while (!$parser->eof()) {
33
            $record = $parser->getCurrentLineRecord();
34
            $recordType = strtoupper(trim($record[1]));
35
            $currentDepth = (int) $record[0];
36
37
            if ($currentDepth <= $depth) {
38
                $parser->back();
39
                break;
40
            }
41
42
            if (!isset($record[2])) {
43
                $record[2] = '';
44
            }
45
46
            switch ($recordType) {
47
                case 'TYPE':
48
                    $fone->setType(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setType() does not exist on PhpGedcom\Record\Indi\Name\Fone. 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

48
                    $fone->/** @scrutinizer ignore-call */ 
49
                           setType(trim($record[2]));
Loading history...
49
                    break;
50
                case 'NPFX':
51
                    $fone->setNpfx(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setNpfx() does not exist on PhpGedcom\Record\Indi\Name\Fone. 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

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

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

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

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

63
                    $fone->/** @scrutinizer ignore-call */ 
64
                           setSurn(trim($record[2]));
Loading history...
64
                    break;
65
                case 'NSFX':
66
                    $fone->setNsfx(trim($record[2]));
0 ignored issues
show
Bug introduced by
The method setNsfx() does not exist on PhpGedcom\Record\Indi\Name\Fone. 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
                    $fone->/** @scrutinizer ignore-call */ 
67
                           setNsfx(trim($record[2]));
Loading history...
67
                    break;
68
                default:
69
                    $parser->logUnhandledRecord(get_class().' @ '.__LINE__);
70
            }
71
72
            $parser->forward();
73
        }
74
75
        return $fone;
76
    }
77
}
78