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

Subm::convert()   F

Complexity

Conditions 21
Paths 513

Size

Total Lines 85
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 21
eloc 48
nc 513
nop 1
dl 0
loc 85
rs 0.6763
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          Xiang Ming <[email protected]>
9
 * @copyright       Copyright (c) 2010-2013, Xiang Ming
10
 * @package         php-gedcom 
11
 * @license         MIT
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace PhpGedcom\Writer;
16
17
/**
18
 *
19
 */
20
class Subm
21
{
22
    /**
23
     * @param \PhpGedcom\Record\Subm $note
24
     * @param int $level
25
     * @return string
26
     */
27
    public static function convert(\PhpGedcom\Record\Subm &$subm)
28
    {
29
        $level = 0;
30
        $output = "";
31
        $_subm = $subm->getSubn();
0 ignored issues
show
Bug introduced by
The method getSubn() does not exist on PhpGedcom\Record\Subm. 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

31
        /** @scrutinizer ignore-call */ 
32
        $_subm = $subm->getSubn();
Loading history...
32
        if(empty($_subm)){
33
            return $output;
34
        }else{
35
            $output.=$level." ".$_subm." SUBM "."\n";
0 ignored issues
show
Bug introduced by
Are you sure $_subm of type PhpGedcom\Record\Subm|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            $output.=$level." "./** @scrutinizer ignore-type */ $_subm." SUBM "."\n";
Loading history...
36
        }
37
        // level up
38
        $level++;
39
40
        // NAME
41
        $name = $subm->getName();
42
        if(!empty($name)){
43
            $output.=$level." NAME ".$name."\n";
44
        }
45
        // $chan
46
        $chan = $subm->getChan();
47
        if($chan){
0 ignored issues
show
introduced by
$chan is of type PhpGedcom\Record\Chan, thus it always evaluated to true.
Loading history...
48
            $_convert = \PhpGedcom\Writer\Chan::convert($chan, $level);
49
            $output.=$_convert;
50
        }
51
52
        // $addr
53
        $addr = $subm->getAddr();
54
        if($addr){
0 ignored issues
show
introduced by
$addr is of type PhpGedcom\Record\Addr, thus it always evaluated to true.
Loading history...
55
            $_convert = \PhpGedcom\Writer\Addr::convert($addr, $level);
56
            $output.=$_convert;
57
        }
58
59
        // $rin
60
        $rin = $subm->getRin();
61
        if(!empty($rin)){
62
            $output.=$level." RIN ".$rin."\n";
63
        }
64
65
        // $rfn
66
        $rfn = $subm->getRfn();
67
        if(!empty($rfn)){
68
            $output.=$level." RFN ".$rfn."\n";
69
        }
70
71
        // $lang = array()
72
        $langs = $subm->getLang();
73
        if(!empty($langs) && count($langs) > 0){
74
            foreach($langs as $item){
75
                if($item){
76
                    $_convert = $level." LANG ".$item."\n";
77
                    $output.=$_convert;
78
                }
79
            }
80
        }
81
82
        // $phon = array()
83
        $phon = $subm->getLang();
84
        if(!empty($phon) && count($phon) > 0){
85
            foreach($phon as $item){
86
                if($item){
87
                    $_convert = \PhpGedcom\Writer\Phon::convert($item, $level);
88
                    $output.= $_convert;
89
                }
90
            }
91
        }
92
93
        // $obje = array()
94
        $obje = $subm->getObje();
95
        if(!empty($obje) && count($obje) > 0){
96
            foreach($obje as $item){
97
                $_convert = \PhpGedcom\Writer\ObjeRef::convert($item, $level);
98
                $output.=$_convert;
99
            }
100
        }
101
102
        // note
103
        $note = $subm->getNote();
104
        if(!empty($note) && count($note) > 0){
105
            foreach($note as $item){
106
                $_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level);
107
                $output.=$_convert;
108
            }
109
        }
110
        
111
        return $output;
112
    }
113
}
114