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

Even::convert()   F

Complexity

Conditions 22
Paths 8192

Size

Total Lines 99
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 55
nc 8192
nop 2
dl 0
loc 99
rs 0
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\Indi;
16
17
/**
18
 *
19
 */
20
class Even
21
{
22
    /**
23
     * @param \PhpGedcom\Record\Indi\Even $even
24
     * @param int $level
25
     * @return string
26
     */
27
    public static function convert(\PhpGedcom\Record\Indi\Even &$even, $level = 0)
28
    {
29
        $output = "";
30
31
        // $_attr;
32
        $attr = $even->getAttr();
0 ignored issues
show
Bug introduced by
The method getAttr() does not exist on PhpGedcom\Record\Indi\Even. 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

32
        /** @scrutinizer ignore-call */ 
33
        $attr = $even->getAttr();
Loading history...
33
        if(!empty($attr)){
34
            $output.=$level." EVEN ".$attr."\n";
0 ignored issues
show
Bug introduced by
Are you sure $attr of type PhpGedcom\Record\Indi\Even|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

34
            $output.=$level." EVEN "./** @scrutinizer ignore-type */ $attr."\n";
Loading history...
35
        }else{
36
            $output = $level." EVEN\n";
37
        }
38
        $level++;
39
40
        // $type;
41
        $type = $even->getType();
42
        if(!empty($type)){
43
            $output.=$level." TYPE ".$type."\n";
44
        }
45
46
        // $date;
47
        $date = $even->getDate();
48
        if(!empty($date)){
49
            $output.=$level." DATE ".$date."\n";
50
        }
51
        
52
        // Plac
53
        $plac = $even->getPlac();
54
        if(!empty($plac)){
55
            $_convert = \PhpGedcom\Writer\Indi\Even\Plac::convert($plac, $level);
56
            $output.=$_convert;
57
        }
58
59
        // $caus;
60
        $caus = $even->getCaus();
61
        if(!empty($caus)){
62
            $output.=$level." CAUS ".$caus."\n";
63
        }
64
65
        // $age;
66
        $age = $even->getAge();
67
        if(!empty($age)){
68
            $output.=$level." AGE ".$age."\n";
69
        }
70
71
        // $addr
72
        $addr = $even->getAddr();
73
        if(!empty($addr)){
74
            $_convert = \PhpGedcom\Writer\Addr::convert($addr, $level);
75
            $output.=$_convert;
76
        }
77
78
        // $phon = array()
79
        $phon = $even->getPhon();
80
        if(!empty($phon) && count($phon) > 0){
81
            foreach($phon as $item){
82
                $_convert = \PhpGedcom\Writer\Phon::convert($item, $level);
83
                $output.=$_convert;
84
            }
85
        }
86
        // $agnc
87
        $agnc = $even->getAgnc();
88
        if(!empty($agnc)){
89
            $output.=$level." AGNC ".$agnc."\n";
90
        }
91
92
        // $ref = array();
93
        // This is not in parser
94
95
        // $obje = array();
96
        $obje = $even->getObje();
97
        if(!empty($obje) && count($obje) > 0){
98
            foreach($obje as $item){
99
                $_convert = \PhpGedcom\Writer\ObjeRef::convert($item, $level);
100
                $output.=$_convert;
101
            }
102
        }
103
        // $sour = array();
104
        $sour = $even->getSour();
105
        if(!empty($sour) && count($sour) > 0){
106
            foreach($sour as $item){
107
                $_convert = \PhpGedcom\Writer\SourRef::convert($item, $level);
108
                $output.=$_convert;
109
            }
110
        }
111
        // $note = array();
112
        $note = $even->getSour();
113
        if(!empty($note) && count($note) > 0){
114
            foreach($note as $item){
115
                $_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level);
116
                $output.=$_convert;
117
            }
118
        }
119
        // Record\Chan
120
        $chan = $even->getChan();
121
        if(!empty($chan) ){
122
            $_convert = \PhpGedcom\Writer\Chan::convert($item, $level);
123
            $output.=$_convert;
124
        }
125
        return $output;
126
    }
127
}
128