Sour::convert()   F
last analyzed

Complexity

Conditions 20
Paths 4097

Size

Total Lines 97
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 97
c 0
b 0
f 0
rs 0
cc 20
nc 4097
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 Sour
18
{
19
    /**
20
     * @param int $level
21
     *
22
     * @return string
23
     */
24
    public static function convert(\Gedcom\Record\Sour &$sour, $level)
25
    {
26
        $output = '';
27
        $_sour = $sour->getSour();
28
        if (empty($_sour)) {
29
            return $output;
30
        } else {
31
            $output .= $level.' '.$_sour.' SOUR '."\n";
32
        }
33
        // level up
34
        $level++;
35
36
        // TITL
37
        $titl = $sour->getType();
0 ignored issues
show
Bug introduced by
The method getType() does not exist on Gedcom\Record\Sour. 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

37
        /** @scrutinizer ignore-call */ 
38
        $titl = $sour->getType();
Loading history...
38
        if (!empty($type)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $type seems to never exist and therefore empty should always be true.
Loading history...
39
            $output .= $level.' TITL '.$titl."\n";
0 ignored issues
show
Bug introduced by
Are you sure $titl of type Gedcom\Record\Sour|mixed|null 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

39
            $output .= $level.' TITL './** @scrutinizer ignore-type */ $titl."\n";
Loading history...
40
        }
41
42
        // RIN
43
        $rin = $sour->getRin();
44
        if (!empty($rin)) {
45
            $output .= $level.' RIN '.$rin."\n";
46
        }
47
48
        // AUTH
49
        $auth = $sour->getAuth();
50
        if (!empty($auth)) {
51
            $output .= $level.' AUTH '.$auth."\n";
52
        }
53
54
        // TEXT
55
        $text = $sour->getText();
56
        if (!empty($text)) {
57
            $output .= $level.' TEXT '.$text."\n";
58
        }
59
60
        // PUBL
61
        $publ = $sour->getPubl();
62
        if (!empty($publ)) {
63
            $output .= $level.' PUBL '.$publ."\n";
64
        }
65
66
        // ABBR
67
        $abbr = $sour->getAbbr();
68
        if (!empty($abbr)) {
69
            $output .= $level.' ABBR '.$abbr."\n";
70
        }
71
72
        // REPO
73
        $repo = $sour->getRepo();
74
        if (!empty($repo)) {
75
            $_convert = \Gedcom\Writer\RepoRef::convert($repo, $level);
0 ignored issues
show
Bug introduced by
$repo of type Gedcom\Record\Repo is incompatible with the type Gedcom\Record\RepoRef expected by parameter $reporef of Gedcom\Writer\RepoRef::convert(). ( Ignorable by Annotation )

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

75
            $_convert = \Gedcom\Writer\RepoRef::convert(/** @scrutinizer ignore-type */ $repo, $level);
Loading history...
76
            $output .= $_convert;
77
        }
78
79
        // NOTE array
80
        $note = $sour->getNote();
81
        if (!empty($note) && count($note) > 0) {
82
            foreach ($note as $item) {
83
                $_convert = \Gedcom\Writer\NoteRef::convert($item, $level);
84
                $output .= $_convert;
85
            }
86
        }
87
88
        // DATA
89
        $data = $sour->getData();
90
        if (!empty($data)) {
91
            $_convert = \Gedcom\Writer\Sour\Data::convert($data, $level);
0 ignored issues
show
Bug introduced by
$data of type string is incompatible with the type Gedcom\Record\Sour\Data expected by parameter $data of Gedcom\Writer\Sour\Data::convert(). ( Ignorable by Annotation )

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

91
            $_convert = \Gedcom\Writer\Sour\Data::convert(/** @scrutinizer ignore-type */ $data, $level);
Loading history...
92
            $output .= $_convert;
93
        }
94
95
        // OBJE array
96
        $obje = $sour->getObje();
97
        if (!empty($obje) && count($obje) > 0) {
98
            foreach ($obje as $item) {
99
                $_convert = \Gedcom\Writer\ObjeRef::convert($item, $level);
100
                $output .= $_convert;
101
            }
102
        }
103
104
        // REFN array
105
        $refn = $sour->getRefn();
106
        if (!empty($refn) && count($refn) > 0) {
107
            foreach ($refn as $item) {
108
                $_convert = \Gedcom\Writer\Refn::convert($item, $level);
109
                $output .= $_convert;
110
            }
111
        }
112
113
        // chan
114
        $chan = $sour->getChan();
115
        if (!empty($chan)) {
116
            $_convert = \Gedcom\Writer\Chan::convert($chan, $level);
117
            $output .= $_convert;
118
        }
119
120
        return $output;
121
    }
122
}
123