Passed
Push — master ( 6f3564...5d9325 )
by Curtis
12:40
created

Lds::read()   B

Complexity

Conditions 10
Paths 16

Size

Total Lines 52
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 38
nc 16
nop 7
dl 0
loc 52
rs 7.6666
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
namespace FamilyTree365\LaravelGedcom\Utils\Exporter\Indi;
4
5
use FamilyTree365\LaravelGedcom\Models\PersonLds;
6
use FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef;
7
use FamilyTree365\LaravelGedcom\Utils\Importer\SourRef;
8
9
class Lds
10
{
11
    /**
12
     * Gedcom\Record\Indi\Lds $lds
13
     * String $group
14
     * Integer $group_id.
15
     */
16
    public static function read($conn, \Gedcom\Record\Indi\Lds $lds, $group = '', $group_id = 0, $type = '', $sour_ids = [], $obje_ids = [])
17
    {
18
        $stat = $lds->getStat();
19
        $date = $lds->getDate();
20
        $plac = $lds->getPlac();
21
        $temp = $lds->getTemp();
22
23
        $slgc_famc = '';
24
        if ($type == 'SLGC') {
25
            $slgc_famc = $lds->getFamc();
26
        }
27
        // store refn
28
        $key = [
29
            'group'     => $group,
30
            'gid'       => $group_id,
31
            'type'      => $type,
32
            'stat'      => $stat,
33
            'date'      => $date,
34
            'plac'      => $plac,
35
            'temp'      => $temp,
36
            'slgc_famc' => $slgc_famc,
37
        ];
38
        $data = [
39
            'group'     => $group,
40
            'gid'       => $group_id,
41
            'type'      => $type,
42
            'stat'      => $stat,
43
            'date'      => $date,
44
            'plac'      => $plac,
45
            'temp'      => $temp,
46
            'slgc_famc' => $slgc_famc,
47
        ];
48
        $record = PersonLds::on($conn)->updateOrCreate($key, $data);
49
50
        $_group = 'indi_lds';
51
        $_gid = $record->id;
52
        // add sour
53
        $sour = $lds->getSour();
54
        if ($sour && count($sour) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $sour can also be of type Gedcom\Record\Indi\Lds; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

54
        if ($sour && count(/** @scrutinizer ignore-type */ $sour) > 0) {
Loading history...
55
            foreach ($sour as $item) {
56
                if ($item) {
57
                    SourRef::read($conn, $item, $_group, $_gid, $sour_ids, $obje_ids);
58
                }
59
            }
60
        }
61
62
        // add note
63
        $note = $lds->getNote();
64
        if ($note && count($note) > 0) {
65
            foreach ($note as $item) {
66
                if ($item) {
67
                    NoteRef::read($conn, $item, $_group, $_gid);
68
                }
69
            }
70
        }
71
    }
72
}
73