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

Head::convert()   F

Complexity

Conditions 13
Paths 4096

Size

Total Lines 103
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 45
nc 4096
nop 2
dl 0
loc 103
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
 * @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 Head
21
{
22
    /**
23
     * @param \PhpGedcom\Record\Head $head
24
     * @param string $format
25
     * @return string
26
     */
27
    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

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