Name::convert()   D
last analyzed

Complexity

Conditions 14
Paths 257

Size

Total Lines 61
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 61
c 0
b 0
f 0
rs 4.7208
cc 14
nc 257
nop 2

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          Xiang Ming <[email protected]>
9
 * @copyright       Copyright (c) 2010-2013, Xiang Ming
10
 * @license         MIT
11
 *
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace Gedcom\Writer\Indi;
16
17
class Name
18
{
19
    /**
20
     * @param \Gedcom\Record\Indi\Name $attr
21
     * @param int                      $level
22
     *
23
     * @return string
24
     */
25
    public static function convert(\Gedcom\Record\Indi\Name &$name, $level = 0)
26
    {
27
        $output = '';
28
        // NAME
29
        $_name = $name->getName();
30
        if (empty($_name)) {
31
            return $output;
32
        }
33
        $output .= $level.' NAME '.$_name."\n";
34
        // level up
35
        $level++;
36
37
        // NPFX
38
        $npfx = $name->getNpfx();
39
        if (!empty($npfx)) {
40
            $output .= $level.' NPFX '.$npfx."\n";
41
        }
42
43
        // GIVN
44
        $givn = $name->getGivn();
45
        if (!empty($givn)) {
46
            $output .= $level.' GIVN '.$givn."\n";
47
        }
48
        // NICK
49
        $nick = $name->getNick();
50
        if (!empty($nick)) {
51
            $output .= $level.' NICK '.$nick."\n";
52
        }
53
        // SPFX
54
        $spfx = $name->getSpfx();
55
        if (!empty($spfx)) {
56
            $output .= $level.' SPFX '.$spfx."\n";
57
        }
58
        // SURN
59
        $surn = $name->getSurn();
60
        if (!empty($surn)) {
61
            $output .= $level.' SURN '.$surn."\n";
62
        }
63
        // NSFX
64
        $nsfx = $name->getNsfx();
65
        if (!empty($nsfx)) {
66
            $output .= $level.' NSFX '.$nsfx."\n";
67
        }
68
        // SOUR
69
        $sour = $name->getSour();
0 ignored issues
show
Bug introduced by
The method getSour() does not exist on Gedcom\Record\Indi\Name. 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

69
        /** @scrutinizer ignore-call */ 
70
        $sour = $name->getSour();
Loading history...
70
        if (!empty($sour) && count($sour) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $sour can also be of type Gedcom\Record\Indi\Name; 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

70
        if (!empty($sour) && count(/** @scrutinizer ignore-type */ $sour) > 0) {
Loading history...
71
            foreach ($sour as $item) {
72
                $_convert = \Gedcom\Writer\SourRef::convert($item, $level);
73
                $output .= $_convert;
74
            }
75
        }
76
        // note
77
        $note = $name->getSour();
78
        if (!empty($note) && count($note) > 0) {
79
            foreach ($note as $item) {
80
                $_convert = \Gedcom\Writer\NoteRef::convert($item, $level);
81
                $output .= $_convert;
82
            }
83
        }
84
85
        return $output;
86
    }
87
}
88