Obje::convert()   D
last analyzed

Complexity

Conditions 16
Paths 257

Size

Total Lines 78
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 78
c 0
b 0
f 0
rs 4.0208
cc 16
nc 257
nop 1

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 Obje
18
{
19
    /**
20
     * @param \Gedcom\Record\Obje $sour
21
     * @param int                 $level
22
     *
23
     * @return string
24
     */
25
    public static function convert(\Gedcom\Record\Obje &$obje)
26
    {
27
        $level = 0;
28
        $output = '';
29
        $id = $obje->getId();
0 ignored issues
show
Bug introduced by
The method getId() does not exist on Gedcom\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

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

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

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

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

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

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

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

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

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

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

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

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

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

89
        /** @scrutinizer ignore-call */ 
90
        $chan = $obje->getChan();
Loading history...
90
        if ($chan) {
91
            $_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\Obje; 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

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

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

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