Fam::convert()   F
last analyzed

Complexity

Conditions 38
Paths 12289

Size

Total Lines 127
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 70
dl 0
loc 127
c 0
b 0
f 0
rs 0
cc 38
nc 12289
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;
16
17
class Fam
18
{
19
    /**
20
     * @param \Gedcom\Record\Fam $sour
21
     * @param int                $level
22
     *
23
     * @return string
24
     */
25
    public static function convert(\Gedcom\Record\Fam &$fam, $level = 0)
26
    {
27
        $output = '';
28
        $id = $fam->getId();
0 ignored issues
show
Bug introduced by
The method getId() does not exist on Gedcom\Record\Fam. 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

28
        /** @scrutinizer ignore-call */ 
29
        $id = $fam->getId();
Loading history...
29
        if (empty($id)) {
30
            return $output;
31
        } else {
32
            $output .= $level.' @'.$id.'@ FAM '."\n";
0 ignored issues
show
Bug introduced by
Are you sure $id of type Gedcom\Record\Fam|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.' @'./** @scrutinizer ignore-type */ $id.'@ FAM '."\n";
Loading history...
33
        }
34
        // level up
35
        $level++;
36
37
        // HUSB
38
        $husb = $fam->getHusb();
0 ignored issues
show
Bug introduced by
The method getHusb() does not exist on Gedcom\Record\Fam. 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

38
        /** @scrutinizer ignore-call */ 
39
        $husb = $fam->getHusb();
Loading history...
39
        if (!empty($husb)) {
40
            $output .= $level.' HUSB @'.$husb."@\n";
0 ignored issues
show
Bug introduced by
Are you sure $husb of type Gedcom\Record\Fam|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

40
            $output .= $level.' HUSB @'./** @scrutinizer ignore-type */ $husb."@\n";
Loading history...
41
        }
42
43
        // WIFE
44
        $wife = $fam->getWife();
0 ignored issues
show
Bug introduced by
The method getWife() does not exist on Gedcom\Record\Fam. 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

44
        /** @scrutinizer ignore-call */ 
45
        $wife = $fam->getWife();
Loading history...
45
        if (!empty($wife)) {
46
            $output .= $level.' WIFE @'.$wife."@\n";
0 ignored issues
show
Bug introduced by
Are you sure $wife of type Gedcom\Record\Fam|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

46
            $output .= $level.' WIFE @'./** @scrutinizer ignore-type */ $wife."@\n";
Loading history...
47
        }
48
49
        // CHIL
50
        $chil = $fam->getChil();
0 ignored issues
show
Bug introduced by
The method getChil() does not exist on Gedcom\Record\Fam. 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

50
        /** @scrutinizer ignore-call */ 
51
        $chil = $fam->getChil();
Loading history...
51
        if (!empty($chil) && count($chil) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $chil can also be of type Gedcom\Record\Fam; 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

51
        if (!empty($chil) && count(/** @scrutinizer ignore-type */ $chil) > 0) {
Loading history...
52
            foreach ($chil as $item) {
53
                if ($item) {
54
                    $_convert = $level.' CHIL @'.$item."@\n";
55
                    $output .= $_convert;
56
                }
57
            }
58
        }
59
        // NCHI
60
        $nchi = $fam->getNchi();
0 ignored issues
show
Bug introduced by
The method getNchi() does not exist on Gedcom\Record\Fam. 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
        /** @scrutinizer ignore-call */ 
61
        $nchi = $fam->getNchi();
Loading history...
61
        if (!empty($nchi)) {
62
            $output .= $level.' NCHI '.$nchi."\n";
0 ignored issues
show
Bug introduced by
Are you sure $nchi of type Gedcom\Record\Fam|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

62
            $output .= $level.' NCHI './** @scrutinizer ignore-type */ $nchi."\n";
Loading history...
63
        }
64
65
        // SUBM array
66
        $subm = $fam->getSubm();
0 ignored issues
show
Bug introduced by
The method getSubm() does not exist on Gedcom\Record\Fam. 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
        /** @scrutinizer ignore-call */ 
67
        $subm = $fam->getSubm();
Loading history...
67
68
        if (!empty($subm) && count($subm) > 0) {
69
            foreach ($subm as $item) {
70
                if ($item) {
71
                    $output .= $level.' SUBM '.$item."\n";
72
                }
73
            }
74
        }
75
76
        // RIN
77
        $rin = $fam->getRin();
0 ignored issues
show
Bug introduced by
The method getRin() does not exist on Gedcom\Record\Fam. 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

77
        /** @scrutinizer ignore-call */ 
78
        $rin = $fam->getRin();
Loading history...
78
        if (!empty($rin)) {
79
            $output .= $level.' RIN '.$rin."\n";
0 ignored issues
show
Bug introduced by
Are you sure $rin of type Gedcom\Record\Fam|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

79
            $output .= $level.' RIN './** @scrutinizer ignore-type */ $rin."\n";
Loading history...
80
        }
81
        // CHAN
82
        $chan = $fam->getChan();
0 ignored issues
show
Bug introduced by
The method getChan() does not exist on Gedcom\Record\Fam. 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

82
        /** @scrutinizer ignore-call */ 
83
        $chan = $fam->getChan();
Loading history...
83
        if (!empty($chan)) {
84
            $_convert = \Gedcom\Writer\Chan::convert($chan, $level);
0 ignored issues
show
Bug introduced by
It seems like $chan can also be of type Gedcom\Record\Fam; however, parameter $chan of Gedcom\Writer\Chan::convert() does only seem to accept Gedcom\Record\Chan, 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

84
            $_convert = \Gedcom\Writer\Chan::convert(/** @scrutinizer ignore-type */ $chan, $level);
Loading history...
85
            $output .= $_convert;
86
        }
87
        // SLGS
88
        $slgs = $fam->getSlgs();
0 ignored issues
show
Bug introduced by
The method getSlgs() does not exist on Gedcom\Record\Fam. 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

88
        /** @scrutinizer ignore-call */ 
89
        $slgs = $fam->getSlgs();
Loading history...
89
        if (!empty($slgs) && count($slgs) > 0) {
90
            if ($slgs) {
91
                $_convert = \Gedcom\Writer\Fam\Slgs::convert($item, $level);
92
                $output .= $_convert;
93
            }
94
        }
95
96
        // REFN array
97
        $refn = $fam->getRefn();
0 ignored issues
show
Bug introduced by
The method getRefn() does not exist on Gedcom\Record\Fam. 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

97
        /** @scrutinizer ignore-call */ 
98
        $refn = $fam->getRefn();
Loading history...
98
        if (!empty($refn) && count($refn) > 0) {
99
            foreach ($refn as $item) {
100
                if ($item) {
101
                    $_convert = \Gedcom\Writer\Refn::convert($item, $level);
102
                    $output .= $_convert;
103
                }
104
            }
105
        }
106
107
        // NOTE array
108
        $note = $fam->getNote();
0 ignored issues
show
Bug introduced by
The method getNote() does not exist on Gedcom\Record\Fam. 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

108
        /** @scrutinizer ignore-call */ 
109
        $note = $fam->getNote();
Loading history...
109
        if (!empty($note) && count($note) > 0) {
110
            foreach ($note as $item) {
111
                if ($item) {
112
                    $_convert = \Gedcom\Writer\NoteRef::convert($item, $level);
113
                    $output .= $_convert;
114
                }
115
            }
116
        }
117
118
        // SOUR
119
        $sour = $fam->getSour();
0 ignored issues
show
Bug introduced by
The method getSour() does not exist on Gedcom\Record\Fam. 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

119
        /** @scrutinizer ignore-call */ 
120
        $sour = $fam->getSour();
Loading history...
120
        if (!empty($sour) && count($sour) > 0) {
121
            foreach ($sour as $item) {
122
                if ($item) {
123
                    $_convert = \Gedcom\Writer\SourRef::convert($item, $level);
124
                    $output .= $_convert;
125
                }
126
            }
127
        }
128
129
        // OBJE
130
        $obje = $fam->getObje();
0 ignored issues
show
Bug introduced by
The method getObje() does not exist on Gedcom\Record\Fam. 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

130
        /** @scrutinizer ignore-call */ 
131
        $obje = $fam->getObje();
Loading history...
131
        if (!empty($obje) && count($obje) > 0) {
132
            foreach ($obje as $item) {
133
                if ($item) {
134
                    $_convert = \Gedcom\Writer\ObjeRef::convert($item, $level);
135
                    $output .= $_convert;
136
                }
137
            }
138
        }
139
140
        // EVEN
141
        $even = $fam->getAllEven();
142
        if (!empty($even) && count($even) > 0) {
143
            foreach ($even as $item) {
144
                if ($item) {
145
                    $_convert = \Gedcom\Writer\Fam\Even::convert($item, $level);
146
                    $output .= $_convert;
147
                }
148
            }
149
        }
150
151
        return $output;
152
    }
153
}
154