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

Obje::convert()   D

Complexity

Conditions 16
Paths 257

Size

Total Lines 78
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 40
nc 257
nop 1
dl 0
loc 78
rs 4.0208
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 Obje
21
{
22
    /**
23
     * @param \PhpGedcom\Record\Obje $sour
24
     * @param int $level
25
     * @return string
26
     */
27
    public static function convert(\PhpGedcom\Record\Obje &$obje)
28
    {
29
        $level = 0;
30
        $output = "";
31
        $id = $obje->getId();
0 ignored issues
show
Bug introduced by
The method getId() does not exist on PhpGedcom\Record\Obje. 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

31
        /** @scrutinizer ignore-call */ 
32
        $id = $obje->getId();
Loading history...
32
        if($id){
33
            $output.=$level." ".$id." OBJE\n";
0 ignored issues
show
Bug introduced by
Are you sure $id of type PhpGedcom\Record\Obje|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

33
            $output.=$level." "./** @scrutinizer ignore-type */ $id." OBJE\n";
Loading history...
34
        }else{
35
            return $output;
36
        }
37
38
        // level up
39
        $level++;
40
41
        // FORM
42
        $form = $obje->getName();
0 ignored issues
show
Bug introduced by
The method getName() does not exist on PhpGedcom\Record\Obje. 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

42
        /** @scrutinizer ignore-call */ 
43
        $form = $obje->getName();
Loading history...
43
        if($form){
44
            $output.=$level." FORM ".$form."\n";
0 ignored issues
show
Bug introduced by
Are you sure $form of type PhpGedcom\Record\Obje|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

44
            $output.=$level." FORM "./** @scrutinizer ignore-type */ $form."\n";
Loading history...
45
        }
46
47
        // TITL
48
        $titl = $obje->getTitl();
0 ignored issues
show
Bug introduced by
The method getTitl() does not exist on PhpGedcom\Record\Obje. 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

48
        /** @scrutinizer ignore-call */ 
49
        $titl = $obje->getTitl();
Loading history...
49
        if($titl){
50
            $output.=$level." TITL ".$titl."\n";
0 ignored issues
show
Bug introduced by
Are you sure $titl of type PhpGedcom\Record\Obje|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

50
            $output.=$level." TITL "./** @scrutinizer ignore-type */ $titl."\n";
Loading history...
51
        }
52
53
        // OBJE 
54
        // This is same as FORM
55
56
        // RIN
57
        $rin = $obje->getRin();
0 ignored issues
show
Bug introduced by
The method getRin() does not exist on PhpGedcom\Record\Obje. 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

57
        /** @scrutinizer ignore-call */ 
58
        $rin = $obje->getRin();
Loading history...
58
        if($rin){
59
            $output.=$level." RIN ".$rin."\n";
0 ignored issues
show
Bug introduced by
Are you sure $rin of type PhpGedcom\Record\Obje|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

59
            $output.=$level." RIN "./** @scrutinizer ignore-type */ $rin."\n";
Loading history...
60
        }
61
62
        // REFN
63
        $refn = $obje->getRefn();
0 ignored issues
show
Bug introduced by
The method getRefn() does not exist on PhpGedcom\Record\Obje. 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

63
        /** @scrutinizer ignore-call */ 
64
        $refn = $obje->getRefn();
Loading history...
64
        if(!empty($refn) && count($refn) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $refn can also be of type PhpGedcom\Record\Obje; however, parameter $var 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

64
        if(!empty($refn) && count(/** @scrutinizer ignore-type */ $refn) > 0) {
Loading history...
65
            foreach($refn as $item){
66
                if($item){
67
                    $_convert = \PhpGedcom\Writer\Refn::convert($item, $level);
68
                    $output.=$_convert;
69
                }
70
            }
71
        }
72
73
        // BLOB
74
        $blob = $obje->getBlob();
0 ignored issues
show
Bug introduced by
The method getBlob() does not exist on PhpGedcom\Record\Obje. 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

74
        /** @scrutinizer ignore-call */ 
75
        $blob = $obje->getBlob();
Loading history...
75
        if($blob){
76
            $output.=$level." BLOB ".$blob."\n";
0 ignored issues
show
Bug introduced by
Are you sure $blob of type PhpGedcom\Record\Obje|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

76
            $output.=$level." BLOB "./** @scrutinizer ignore-type */ $blob."\n";
Loading history...
77
        }
78
79
        // NOTE
80
        $note = $obje->getNote();
0 ignored issues
show
Bug introduced by
The method getNote() does not exist on PhpGedcom\Record\Obje. 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

80
        /** @scrutinizer ignore-call */ 
81
        $note = $obje->getNote();
Loading history...
81
        if($note && count($note) > 0) {
82
            foreach($note as $item){
83
                if($item){
84
                    $_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level);
85
                    $output.=$_convert;
86
                }
87
            }
88
        }
89
90
        // CHAN
91
        $chan = $obje->getChan();
0 ignored issues
show
Bug introduced by
The method getChan() does not exist on PhpGedcom\Record\Obje. 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

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

93
            $_convert = \PhpGedcom\Writer\Chan::convert(/** @scrutinizer ignore-type */ $chan, $level);
Loading history...
94
            $output.=$_convert;
95
        }
96
97
        // FILE
98
        $file = $obje->getFile();
0 ignored issues
show
Bug introduced by
The method getFile() does not exist on PhpGedcom\Record\Obje. 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

98
        /** @scrutinizer ignore-call */ 
99
        $file = $obje->getFile();
Loading history...
99
        if($file){
100
            $output.=$level." FILE ".$file."\n";
0 ignored issues
show
Bug introduced by
Are you sure $file of type PhpGedcom\Record\Obje|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

100
            $output.=$level." FILE "./** @scrutinizer ignore-type */ $file."\n";
Loading history...
101
        }
102
103
        // 
104
        return $output;
105
    }
106
}
107