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

FamilyData::getFamily()   A

Complexity

Conditions 3
Paths 28

Size

Total Lines 62
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 41
c 1
b 1
f 0
nc 28
nop 8
dl 0
loc 62
rs 9.264

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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