Passed
Pull Request — master (#58)
by
unknown
06:41 queued 04:01
created

FamilyData   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 49
c 1
b 1
f 0
dl 0
loc 79
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFamily() 0 62 3
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils;
4
5
use FamilyTree365\LaravelGedcom\Models\Family;
6
use FamilyTree365\LaravelGedcom\Models\Person;
7
8
class FamilyData
9
{
10
    /**
11
     * Array of persons ID
12
     * key - old GEDCOM ID
13
     * value - new cyrus_authenticate(connection)                                   sincrement 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 getFamily($conn, $families, $obje_ids = [], $sour_ids = [], $persons_id = [], $note_ids = [], $repo_ids = [], $parentData = [])
0 ignored issues
show
Unused Code introduced by
The parameter $persons_id 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 getFamily($conn, $families, $obje_ids = [], $sour_ids = [], /** @scrutinizer ignore-unused */ $persons_id = [], $note_ids = [], $repo_ids = [], $parentData = [])

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...
Unused Code introduced by
The parameter $repo_ids 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 getFamily($conn, $families, $obje_ids = [], $sour_ids = [], $persons_id = [], $note_ids = [], /** @scrutinizer ignore-unused */ $repo_ids = [], $parentData = [])

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...
Unused Code introduced by
The parameter $note_ids 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 getFamily($conn, $families, $obje_ids = [], $sour_ids = [], $persons_id = [], /** @scrutinizer ignore-unused */ $note_ids = [], $repo_ids = [], $parentData = [])

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
        $familyData = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $familyData is dead and can be removed.
Loading history...
28
        $persons_id = [];
29
30
        try {
31
            foreach ($families as $family) {
32
                $g_id = $family->getId();
0 ignored issues
show
Unused Code introduced by
The assignment to $g_id is dead and can be removed.
Loading history...
33
                $resn = $family->getResn();
0 ignored issues
show
Unused Code introduced by
The assignment to $resn is dead and can be removed.
Loading history...
34
                $husb = $family->getHusb();
35
                $wife = $family->getWife();
36
37
                // string
38
                $nchi = $family->getNchi();
39
                $rin = $family->getRin();
40
41
                // array
42
                $subm = $family->getSubm();
0 ignored issues
show
Unused Code introduced by
The assignment to $subm is dead and can be removed.
Loading history...
43
                $_slgs = $family->getSlgs();
0 ignored issues
show
Unused Code introduced by
The assignment to $_slgs is dead and can be removed.
Loading history...
44
45
                $description = null;
46
                $type_id = 0;
47
48
                $children = $family->getChil();
0 ignored issues
show
Unused Code introduced by
The assignment to $children is dead and can be removed.
Loading history...
49
                $events = $family->getAllEven();
0 ignored issues
show
Unused Code introduced by
The assignment to $events is dead and can be removed.
Loading history...
50
                $_note = $family->getNote();
0 ignored issues
show
Unused Code introduced by
The assignment to $_note is dead and can be removed.
Loading history...
51
                $_obje = $family->getObje();
0 ignored issues
show
Unused Code introduced by
The assignment to $_obje is dead and can be removed.
Loading history...
52
                $_sour = $family->getSour();
0 ignored issues
show
Unused Code introduced by
The assignment to $_sour is dead and can be removed.
Loading history...
53
                $_refn = $family->getRefn();
0 ignored issues
show
Unused Code introduced by
The assignment to $_refn is dead and can be removed.
Loading history...
54
55
                $chan = $family->getChan();
0 ignored issues
show
Unused Code introduced by
The assignment to $chan is dead and can be removed.
Loading history...
56
57
                $husband_key = array_search($husb, array_column($parentData, 'gid'));
58
                $husband_uid = $parentData[$husband_key]['uid'] ?? null;
59
                $husband_id = Person::where('uid', $husband_uid)->first()->id ?? null;
60
61
                $wife_key = array_search($wife, array_column($parentData, 'gid'));
62
                $wife_uid = $parentData[$wife_key]['uid'] ?? null;
63
                $wife_id = Person::where('uid', $wife_uid)->first()->id ?? null;
64
65
                $persons_id[$husb] = $husband_id;
66
                $persons_id[$wife] = $wife_id;
67
68
                $value = [
69
                    'husband_id'  => $husband_id,
70
                    'wife_id'     => $wife_id,
71
                    'description' => $description,
72
                    'type_id'     => $type_id,
73
                    'nchi'        => $nchi,
74
                    'rin'         => $rin,
75
                ];
76
77
                Family::on($conn)->updateOrCreate($value, $value);
78
79
            }
80
81
            otherFamRecord::insertFamilyData($conn, $persons_id, $families, $obje_ids, $sour_ids);
82
            
83
        } catch (\Exception $e) {
84
            $error = $e->getMessage();
85
86
            return \Log::error($error);
87
        }
88
    }
89
}
90