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

Sour::convert()   F

Complexity

Conditions 20
Paths 4097

Size

Total Lines 97
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

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

41
        /** @scrutinizer ignore-call */ 
42
        $titl = $sour->getType();
Loading history...
42
        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...
43
            $output.=$level." TITL ".$titl."\n";
0 ignored issues
show
Bug introduced by
Are you sure $titl of type PhpGedcom\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

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

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

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