Passed
Pull Request — master (#56)
by
unknown
05:58 queued 02:35
created

ParentData::getPerson()   B

Complexity

Conditions 6
Paths 91

Size

Total Lines 131
Code Lines 107

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 2 Features 1
Metric Value
cc 6
eloc 107
c 8
b 2
f 1
nc 91
nop 4
dl 0
loc 131
rs 7.3777

How to fix   Long Method   

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
namespace FamilyTree365\LaravelGedcom\Utils;
4
5
use FamilyTree365\LaravelGedcom\Models\Family;
6
use FamilyTree365\LaravelGedcom\Models\Person;
7
8
class ParentData
9
{
10
    /**
11
     * Array of persons ID
12
     * key - old GEDCOM ID
13
     * value - new autoincrement ID.
14
     *
15
     * @var string
16
     */
17
    protected $persons_id = [];
18
    protected $subm_ids = [];
19
    protected $sour_ids = [];
20
    protected $obje_ids = [];
21
    protected $note_ids = [];
22
    protected $repo_ids = [];
23
    protected $conn = '';
24
25
    public static function getPerson($conn, $individuals, $obje_ids = [], $sour_ids = [])
26
    {
27
        $ParentData = [];
28
        $a = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
29
30
        try {
31
            foreach ($individuals as $k => $individual) {
32
                $g_id = $individual->getId();
0 ignored issues
show
Unused Code introduced by
The assignment to $g_id is dead and can be removed.
Loading history...
33
                $name = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
34
                $givn = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $givn is dead and can be removed.
Loading history...
35
                $surn = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $surn is dead and can be removed.
Loading history...
36
                $name = '';
37
                $npfx = '';
38
                $givn = '';
39
                $nick = '';
40
                $spfx = '';
41
                $surn = '';
42
                $nsfx = '';
43
                $type = '';
44
                $fone = null; // Gedcom/
0 ignored issues
show
Unused Code introduced by
The assignment to $fone is dead and can be removed.
Loading history...
45
                $romn = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $romn is dead and can be removed.
Loading history...
46
                $names = $individual->getName();
47
                $attr = $individual->getAllAttr();
0 ignored issues
show
Unused Code introduced by
The assignment to $attr is dead and can be removed.
Loading history...
48
                $events = $individual->getAllEven();
0 ignored issues
show
Unused Code introduced by
The assignment to $events is dead and can be removed.
Loading history...
49
                $note = $individual->getNote();
0 ignored issues
show
Unused Code introduced by
The assignment to $note is dead and can be removed.
Loading history...
50
                $indv_sour = $individual->getSour();
0 ignored issues
show
Unused Code introduced by
The assignment to $indv_sour is dead and can be removed.
Loading history...
51
                $alia = $individual->getAlia(); // string array
0 ignored issues
show
Unused Code introduced by
The assignment to $alia is dead and can be removed.
Loading history...
52
                $asso = $individual->getAsso();
0 ignored issues
show
Unused Code introduced by
The assignment to $asso is dead and can be removed.
Loading history...
53
                $subm = $individual->getSubm();
0 ignored issues
show
Unused Code introduced by
The assignment to $subm is dead and can be removed.
Loading history...
54
                $anci = $individual->getAnci();
0 ignored issues
show
Unused Code introduced by
The assignment to $anci is dead and can be removed.
Loading history...
55
                $refn = $individual->getRefn();
0 ignored issues
show
Unused Code introduced by
The assignment to $refn is dead and can be removed.
Loading history...
56
                $obje = $individual->getObje();
0 ignored issues
show
Unused Code introduced by
The assignment to $obje is dead and can be removed.
Loading history...
57
                // object
58
                $bapl = $individual->getBapl();
0 ignored issues
show
Unused Code introduced by
The assignment to $bapl is dead and can be removed.
Loading history...
59
                $conl = $individual->getConl();
0 ignored issues
show
Unused Code introduced by
The assignment to $conl is dead and can be removed.
Loading history...
60
                $endl = $individual->getEndl();
0 ignored issues
show
Unused Code introduced by
The assignment to $endl is dead and can be removed.
Loading history...
61
                $slgc = $individual->getSlgc();
0 ignored issues
show
Unused Code introduced by
The assignment to $slgc is dead and can be removed.
Loading history...
62
                $chan = $individual->getChan();
63
//                $a = $chan->getDatetime() ? '' : '';
64
                $g_id = $individual->getId();
65
66
                if (!empty($names)) {
67
                    $name = current($names)->getName();
68
                    $npfx = current($names)->getNpfx();
69
                    $givn = current($names)->getGivn();
70
                    $nick = current($names)->getNick();
71
                    $spfx = current($names)->getSpfx();
72
                    $surn = current($names)->getSurn();
73
                    $nsfx = current($names)->getNsfx();
74
                    $type = current($names)->getType();
75
                }
76
77
                // array value
78
                $fams = $individual->getFams();  // self family, leave it now, note would be included in family
0 ignored issues
show
Unused Code introduced by
The assignment to $fams is dead and can be removed.
Loading history...
79
                $famc = $individual->getFamc();  // parent family , leave it now, note and pedi would be included in family
0 ignored issues
show
Unused Code introduced by
The assignment to $famc is dead and can be removed.
Loading history...
80
81
                // added to database
82
                // string value
83
                $sex = preg_replace('/[^MF]/', '', $individual->getSex());
84
                $uid = $individual->getUid();
85
                $resn = $individual->getResn();
86
                $rin = $individual->getRin();
87
                $rfn = $individual->getRfn();
88
                $afn = $individual->getAfn();
89
                
90
                $birt = $individual->getBirt();
91
                $birthday = $birt->dateFormatted ?? null;
92
                $birth_year = $birt->year ?? null;
93
                $birthday_dati = $birt->dati ?? null;
94
                $birthday_plac = $birt->plac ?? null;
95
                
96
                $deat = $individual->getDeat();
97
                $deathday = $deat->dateFormatted ?? null;
98
                $death_year = $deat->year ?? null;
99
                $deathday_dati = $deat->dati ?? null;
100
                $deathday_plac = $deat->plac ?? null;
101
                $deathday_caus = $deat->caus ?? null;
102
103
                $buri = $individual->getBuri();
104
                $burial_day = $buri->dateFormatted ?? null;
105
                $burial_year = $buri->year ?? null;
106
                $burial_day_dati = $buri->dati ?? null;
107
                $burial_day_plac = $buri->plac ?? null;
108
109
                if ($givn == '') {
110
                    $givn = $name;
111
                }
112
113
                $config = json_encode(config('database.connections.'.$conn));
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

113
                $config = json_encode(/** @scrutinizer ignore-call */ config('database.connections.'.$conn));
Loading history...
114
                $value = [
115
                    'gid' => $g_id,
116
                    'name' => $name,
117
                    'givn' => $givn,
118
                    'surn' => $surn,
119
                    'sex' => $sex,
120
                    'uid' => $uid,
121
                    'rin' => $rin,
122
                    'resn' => $resn,
123
                    'rfn' => $rfn,
124
                    'afn' => $afn,
125
                    'nick' => $nick,
126
                    'type' => $type,
127
                    'chan' => $chan ? $chan->getDatetime() : null,
128
                    'nsfx' => $nsfx,
129
                    'npfx' => $npfx,
130
                    'spfx' => $spfx,
131
                    'birthday' => $birthday,
132
                    'birth_year' => $birth_year,
133
                    'birthday_dati' => $birthday_dati,
134
                    'birthday_plac' => $birthday_plac,
135
                    'deathday' => $deathday,
136
                    'death_year' => $death_year,
137
                    'deathday_dati' => $deathday_dati,
138
                    'deathday_plac' => $deathday_plac,
139
                    'deathday_caus' => $deathday_caus,
140
                    'burial_day' => $burial_day,
141
                    'burial_year' => $burial_year,
142
                    'burial_day_dati' => $burial_day_dati,
143
                    'burial_day_plac' => $burial_day_plac,
144
                ];
145
146
                $ParentData[] = $value;
147
            }
148
149
            // it's take only 1 second for 3010 record
150
            Person::on($conn)->upsert($ParentData, ['uid']);
151
            otherFields::insertOtherFields($conn, $individuals, $obje_ids, $sour_ids);
152
        } catch (\Exception $e) {
153
            $error = $e->getMessage();
154
155
            return \Log::error($error);
156
        }
157
    }
158
}
159