Writer::convert()   F
last analyzed

Complexity

Conditions 31
Paths 512

Size

Total Lines 88
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
dl 0
loc 88
c 1
b 0
f 0
rs 0.6777
cc 31
nc 512
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          Kristopher Wilson <[email protected]>
9
 * @copyright       Copyright (c) 2010-2013, Kristopher Wilson
10
 * @license         MIT
11
 *
12
 * @link            http://github.com/mrkrstphr/php-gedcom
13
 */
14
15
namespace Gedcom;
16
17
use Gedcom\Writer\Fam;
18
use Gedcom\Writer\Head;
19
use Gedcom\Writer\Indi;
20
use Gedcom\Writer\Note;
21
use Gedcom\Writer\Obje;
22
use Gedcom\Writer\Repo;
23
use Gedcom\Writer\Sour;
24
use Gedcom\Writer\Subm;
25
use Gedcom\Writer\Subn;
26
27
class Writer
28
{
29
    const GEDCOM55 = 'gedcom5.5';
30
31
    protected $_output;
32
33
    /**
34
     * @param        $gedcom The GEDCOM object
0 ignored issues
show
Bug introduced by
The type Gedcom\The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
     * @param string $format The format to convert the GEDCOM object to
36
     *
37
     * @return string The contents of the document in the converted format
38
     */
39
    public static function convert(Gedcom $gedcom, $format = self::GEDCOM55)
40
    {
41
        $head = $gedcom->getHead();
42
        $subn = $gedcom->getSubn();
43
        $subms = $gedcom->getSubm();    // array()
44
        $sours = $gedcom->getSour();    // array()
45
        $indis = $gedcom->getIndi();    // array()
46
        $fams = $gedcom->getFam();      // array()
47
        $notes = $gedcom->getNote();    // array()
48
        $repos = $gedcom->getRepo();    // array()
49
        $objes = $gedcom->getObje();    // array()
50
51
        $output = '0 FORMAT '.$format."\n";
52
53
        // head
54
        if ($head) {
0 ignored issues
show
introduced by
$head is of type Gedcom\Record\Head, thus it always evaluated to true.
Loading history...
55
            $output = Head::convert($head, $format);
56
        }
57
58
        // subn
59
        if ($subn) {
0 ignored issues
show
introduced by
$subn is of type Gedcom\Record\Subn, thus it always evaluated to true.
Loading history...
60
            $output .= Subn::convert($subn);
61
        }
62
63
        // subms
64
        if (!empty($subms) && count($subms) > 0) {
65
            foreach ($subms as $item) {
66
                if ($item) {
67
                    $output .= Subm::convert($item);
68
                }
69
            }
70
        }
71
72
        // sours
73
        if (!empty($sours) && count($sours) > 0) {
74
            foreach ($sours as $item) {
75
                if ($item) {
76
                    $output .= Sour::convert($item, 0);
77
                }
78
            }
79
        }
80
81
        // indis
82
        if (!empty($indis) && count($indis) > 0) {
83
            foreach ($indis as $item) {
84
                if ($item) {
85
                    $output .= Indi::convert($item);
86
                }
87
            }
88
        }
89
90
        // fams
91
        if (!empty($fams) && count($fams) > 0) {
92
            foreach ($fams as $item) {
93
                if ($item) {
94
                    $output .= Fam::convert($item);
95
                }
96
            }
97
        }
98
        // notes
99
        if (!empty($notes) && count($notes) > 0) {
100
            foreach ($notes as $item) {
101
                if ($item) {
102
                    $output .= Note::convert($item);
103
                }
104
            }
105
        }
106
107
        // repos
108
        if (!empty($repos) && count($repos) > 0) {
109
            foreach ($repos as $item) {
110
                if ($item) {
111
                    $output .= Repo::convert($item);
112
                }
113
            }
114
        }
115
        // Objes
116
        if (!empty($objes) && count($objes) > 0) {
117
            foreach ($objes as $item) {
118
                if ($item) {
119
                    $output .= Obje::convert($item);
120
                }
121
            }
122
        }
123
        // EOF
124
        $output .= "0 TRLR\n";
125
126
        return $output;
127
    }
128
}
129