Passed
Push — master ( bd2365...e501a6 )
by Curtis
01:36 queued 01:09
created

ParentData::getPerson()   F

Complexity

Conditions 11
Paths 1707

Size

Total Lines 109
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 2 Features 1
Metric Value
cc 11
eloc 89
c 7
b 2
f 1
nc 1707
nop 4
dl 0
loc 109
rs 2.7599

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
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
29
        try {
30
            foreach ($individuals as $k => $individual) {
31
                $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...
32
                $name = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
33
                $givn = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $givn is dead and can be removed.
Loading history...
34
                $surn = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $surn is dead and can be removed.
Loading history...
35
                $name = '';
36
                $npfx = '';
37
                $givn = '';
38
                $nick = '';
39
                $spfx = '';
40
                $surn = '';
41
                $nsfx = '';
42
                $type = '';
43
                $fone = null; // Gedcom/
0 ignored issues
show
Unused Code introduced by
The assignment to $fone is dead and can be removed.
Loading history...
44
                $romn = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $romn is dead and can be removed.
Loading history...
45
                $names = $individual->getName();
46
                $attr = $individual->getAllAttr();
0 ignored issues
show
Unused Code introduced by
The assignment to $attr is dead and can be removed.
Loading history...
47
                $events = $individual->getAllEven();
0 ignored issues
show
Unused Code introduced by
The assignment to $events is dead and can be removed.
Loading history...
48
                $note = $individual->getNote();
0 ignored issues
show
Unused Code introduced by
The assignment to $note is dead and can be removed.
Loading history...
49
                $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...
50
                $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...
51
                $asso = $individual->getAsso();
0 ignored issues
show
Unused Code introduced by
The assignment to $asso is dead and can be removed.
Loading history...
52
                $subm = $individual->getSubm();
0 ignored issues
show
Unused Code introduced by
The assignment to $subm is dead and can be removed.
Loading history...
53
                $anci = $individual->getAnci();
0 ignored issues
show
Unused Code introduced by
The assignment to $anci is dead and can be removed.
Loading history...
54
                $refn = $individual->getRefn();
0 ignored issues
show
Unused Code introduced by
The assignment to $refn is dead and can be removed.
Loading history...
55
                $obje = $individual->getObje();
0 ignored issues
show
Unused Code introduced by
The assignment to $obje is dead and can be removed.
Loading history...
56
                // object
57
                $bapl = $individual->getBapl();
0 ignored issues
show
Unused Code introduced by
The assignment to $bapl is dead and can be removed.
Loading history...
58
                $conl = $individual->getConl();
0 ignored issues
show
Unused Code introduced by
The assignment to $conl is dead and can be removed.
Loading history...
59
                $endl = $individual->getEndl();
0 ignored issues
show
Unused Code introduced by
The assignment to $endl is dead and can be removed.
Loading history...
60
                $slgc = $individual->getSlgc();
0 ignored issues
show
Unused Code introduced by
The assignment to $slgc is dead and can be removed.
Loading history...
61
                $chan = $individual->getChan();
62
                $g_id = $individual->getId();
63
64
                if (!empty($names)) {
65
                    $name = current($names)->getName();
66
                    $npfx = current($names)->getNpfx();
67
                    $givn = current($names)->getGivn();
68
                    $nick = current($names)->getNick();
69
                    $spfx = current($names)->getSpfx();
70
                    $surn = current($names)->getSurn();
71
                    $nsfx = current($names)->getNsfx();
72
                    $type = current($names)->getType();
73
                }
74
75
                // array value
76
                $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...
77
                $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...
78
79
                // added to database
80
                // string value
81
                $sex = preg_replace('/[^MF]/', '', $individual->getSex());
82
                $uid = $individual->getUid();
83
                $resn = $individual->getResn();
84
                $rin = $individual->getRin();
85
                $rfn = $individual->getRfn();
86
                $afn = $individual->getAfn();
87
                $birthday = strlen($individual->getBirthday()) > 4 ? $individual->getBirthday() : null;
88
                $birth_year = strlen($individual->getBirthday()) === 4 ? $individual->getBirthday() : null;
89
                $deathday = strlen($individual->getDeathday()) > 4 ? $individual->getDeathday() : null;
90
                $death_year = strlen($individual->getDeathday()) === 4 ? $individual->getDeathday() : null;
91
                $burial_day = strlen($individual->getBurialday()) > 4 ? $individual->getBurialday() : null;
92
                $burial_year = strlen($individual->getBurialday()) === 4 ? $individual->getBurialday() : null;
93
94
                if ($givn == '') {
95
                    $givn = $name;
96
                }
97
98
                $config = json_encode(config('database.connections.'.$conn));
0 ignored issues
show
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

98
                $config = json_encode(/** @scrutinizer ignore-call */ config('database.connections.'.$conn));
Loading history...
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
99
                $value = [
100
                    'gid' => $g_id,
101
                    'name' => $name,
102
                    'givn' => $givn,
103
                    'surn' => $surn,
104
                    'sex' => $sex,
105
                    'uid' => $uid,
106
                    'rin' => $rin,
107
                    'resn' => $resn,
108
                    'rfn' => $rfn,
109
                    'afn' => $afn,
110
                    'birthday' => $birthday,
111
                    'birth_year' => $birth_year,
112
                    'deathday' => $deathday,
113
                    'death_year' => $death_year,
114
                    'burial_day' => $burial_day,
115
                    'burial_year' => $burial_year,
116
                    'nick' => $nick,
117
                    'type' => $type,
118
                    'chan' => $chan->getDatetime(),
119
                    'nsfx' => $nsfx,
120
                    'npfx' => $npfx,
121
                    'spfx' => $spfx
122
                ];
123
124
                $ParentData[] = $value;
125
            }
126
127
            // it's take only 1 second for 3010 record
128
            Person::on($conn)->insert($ParentData);
129
            otherFields::insertOtherFields($conn, $individuals, $obje_ids, $sour_ids);
130
        } catch (\Exception $e) {
131
            $error = $e->getMessage();
132
133
            return \Log::error($error);
134
        }
135
    }
136
}
137