Even::convert()   F
last analyzed

Complexity

Conditions 22
Paths 8192

Size

Total Lines 100
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 55
nc 8192
nop 2
dl 0
loc 100
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
 * @license         MIT
11
 *
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace PhpGedcom\Writer\Indi;
16
17
class Even
18
{
19
    /**
20
     * @param \PhpGedcom\Record\Indi\Even $even
21
     * @param int                         $level
22
     *
23
     * @return string
24
     */
25
    public static function convert(\PhpGedcom\Record\Indi\Even &$even, $level = 0)
26
    {
27
        $output = '';
28
29
        // $_attr;
30
        $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

30
        /** @scrutinizer ignore-call */ 
31
        $attr = $even->getAttr();
Loading history...
31
        if (!empty($attr)) {
32
            $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

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