Head::convert()   F
last analyzed

Complexity

Conditions 13
Paths 4096

Size

Total Lines 101
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 45
nc 4096
nop 2
dl 0
loc 101
rs 2.45
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          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 PhpGedcom\Writer;
16
17
class Head
18
{
19
    /**
20
     * @param \PhpGedcom\Record\Head $head
21
     * @param string                 $format
22
     *
23
     * @return string
24
     */
25
    public static function convert(\PhpGedcom\Record\Head &$head, $format = self::GEDCOM55)
0 ignored issues
show
Bug introduced by
The constant PhpGedcom\Writer\Head::GEDCOM55 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Unused Code introduced by
The parameter $format is not used and could be removed. ( Ignorable by Annotation )

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

25
    public static function convert(\PhpGedcom\Record\Head &$head, /** @scrutinizer ignore-unused */ $format = self::GEDCOM55)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        $level = 0;
28
        $output = $level." HEAD\n";
29
30
        // level up
31
        $level++;
32
33
        //SOUR
34
        $sour = $head->getSour();
35
        if ($sour) {
0 ignored issues
show
introduced by
$sour is of type PhpGedcom\Record\Head\Sour, thus it always evaluated to true.
Loading history...
36
            $_convert = \PhpGedcom\Writer\Head\Sour::convert($sour, $level);
37
            $output .= $_convert;
38
        }
39
40
        // DEST
41
        $dest = $head->getDest();
42
        if ($dest) {
43
            $output .= $level.' DEST '.$dest."\n";
44
        }
45
46
        //Subm
47
        $subm = $head->getSubm();
48
        if ($subm) {
49
            $output .= $level.' SUBM '.$subm."\n";
50
        }
51
52
        // SUBN
53
        $subn = $head->getSubn();
54
        if ($subn) {
55
            $output .= $level.' SUBN '.$subn."\n";
56
        }
57
58
        // FILE
59
        $file = $head->getFile();
60
        if ($file) {
61
            $output .= $level.' FILE '.$file."\n";
62
        }
63
64
        // COPR
65
        $copr = $head->getCopr();
66
        if ($copr) {
67
            $output .= $level.' COPR '.$copr."\n";
68
        }
69
70
        // LANG
71
        $lang = $head->getLang();
72
        if ($lang) {
73
            $output .= $level.' LANG '.$lang."\n";
74
        }
75
        // DATE
76
        $date = $head->getDate();
77
        if ($date) {
0 ignored issues
show
introduced by
$date is of type PhpGedcom\Record\Head\Date, thus it always evaluated to true.
Loading history...
78
            $_convert = \PhpGedcom\Writer\Head\Date::convert($date, $level);
79
            $output .= $_convert;
80
        }
81
82
        // GEDC
83
        $gedc = $head->getGedc();
84
        if ($gedc) {
0 ignored issues
show
introduced by
$gedc is of type PhpGedcom\Record\Head\Gedc, thus it always evaluated to true.
Loading history...
85
            $_convert = \PhpGedcom\Writer\Head\Gedc::convert($gedc, $level);
86
            $output .= $_convert;
87
        }
88
89
        // CHAR
90
        $char = $head->getChar();
91
        if ($char) {
0 ignored issues
show
introduced by
$char is of type PhpGedcom\Record\Head\Char, thus it always evaluated to true.
Loading history...
92
            $_convert = \PhpGedcom\Writer\Head\Char::convert($char, $level);
93
            $output .= $_convert;
94
        }
95
        // PLAC
96
        $plac = $head->getPlac();
97
        if ($plac) {
0 ignored issues
show
introduced by
$plac is of type PhpGedcom\Record\Head\Plac, thus it always evaluated to true.
Loading history...
98
            $_convert = \PhpGedcom\Writer\Head\Plac::convert($plac, $level);
99
            $output .= $_convert;
100
        }
101
102
        // NOTE
103
        $note = $head->getNote();
104
        if ($note) {
105
            $output .= $level.' NOTE '.$note."\n";
106
        }
107
        //
108
        /*
109
            +1 SUBM @<XREF:SUBM>@  {1:1}
110
            +1 SUBN @<XREF:SUBN>@  {0:1}
111
            +1 FILE <FILE_NAME>  {0:1}
112
            +1 COPR <COPYRIGHT_GEDCOM_FILE>  {0:1}
113
            +1 GEDC        {1:1}
114
              +2 VERS <VERSION_NUMBER>  {1:1}
115
              +2 FORM <GEDCOM_FORM>  {1:1}
116
            +1 CHAR <CHARACTER_SET>  {1:1}
117
              +2 VERS <VERSION_NUMBER>  {0:1}
118
            +1 LANG <LANGUAGE_OF_TEXT>  {0:1}
119
            +1 PLAC        {0:1}
120
              +2 FORM <PLACE_HIERARCHY>  {1:1}
121
            +1 NOTE <GEDCOM_CONTENT_DESCRIPTION>  {0:1}
122
              +2 [CONT|CONC] <GEDCOM_CONTENT_DESCRIPTION>  {0:M}
123
        */
124
125
        return $output;
126
    }
127
}
128