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

Name::read()   B

Complexity

Conditions 11
Paths 16

Size

Total Lines 71
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 49
nc 16
nop 4
dl 0
loc 71
rs 7.3166
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\PersonName;
6
7
class Name
8
{
9
    /**
10
     * \Gedcom\Record\Indi\Asso $asso
11
     * String $group
12
     * Integer $group_id.
13
     */
14
    public static function read($conn, \Gedcom\Record\Indi\Name $item, $group = '', $group_id = 0)
15
    {
16
        $name = $item->getName();
17
        $type = $item->getType();
18
        $npfx = $item->getNpfx();
19
        $givn = $item->getGivn();
20
        $nick = $item->getNick();
21
        $spfx = $item->getSpfx();
22
        $surn = $item->getSurn();
23
        $nsfx = $item->getNsfx();
24
25
        // store asso
26
        $key = [
27
            'group'=> $group,
28
            'gid'  => $group_id,
29
            'type' => $type,
30
            'name' => $name,
31
            'npfx' => $npfx,
32
            'givn' => $givn,
33
            'nick' => $nick,
34
            'spfx' => $spfx,
35
            'surn' => $surn,
36
            'nsfx' => $nsfx,
37
        ];
38
        $data = [
39
            'group'=> $group,
40
            'gid'  => $group_id,
41
            'type' => $type,
42
            'name' => $name,
43
            'npfx' => $npfx,
44
            'givn' => $givn,
45
            'nick' => $nick,
46
            'spfx' => $spfx,
47
            'surn' => $surn,
48
            'nsfx' => $nsfx,
49
        ];
50
51
        $record = PersonName::on($conn)->updateOrCreate($key, $data);
52
53
        $_group = 'indi_name';
54
        $_gid = $record->id;
55
        // store Note
56
        $note = $item->getNote();
57
        if ($note && count($note) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $note can also be of type Gedcom\Record\Indi\Name; 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

57
        if ($note && count(/** @scrutinizer ignore-type */ $note) > 0) {
Loading history...
58
            foreach ($note as $_item) {
59
                if ($_item) {
60
                    \FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef::read($conn, $_item, $_group, $_gid);
61
                }
62
            }
63
        }
64
65
        // store sourref
66
        $sour = $item->getSour();
67
        if ($sour && count($sour) > 0) {
68
            foreach ($sour as $_item) {
69
                if ($_item) {
70
                    \FamilyTree365\LaravelGedcom\Utils\Importer\SourRef::read($conn, $_item, $_group, $_gid);
71
                }
72
            }
73
        }
74
75
        // store fone
76
        $fone = $item->getFone();
77
        if ($fone != null) {
78
            \FamilyTree365\LaravelGedcom\Utils\Importer\Indi\Name\Fone::read($conn, $fone, $_group, $_gid);
0 ignored issues
show
Bug introduced by
It seems like $fone can also be of type Gedcom\Record\Indi\Name; however, parameter $item of FamilyTree365\LaravelGed...\Indi\Name\Fone::read() does only seem to accept Gedcom\Record\Indi\Name\Fone, 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

78
            \FamilyTree365\LaravelGedcom\Utils\Importer\Indi\Name\Fone::read($conn, /** @scrutinizer ignore-type */ $fone, $_group, $_gid);
Loading history...
79
        }
80
81
        // store romn
82
        $romn = $item->getRomn();
83
        if ($romn != null) {
84
            \FamilyTree365\LaravelGedcom\Utils\Importer\Indi\Name\Romn::read($conn, $romn, $_group, $_gid);
0 ignored issues
show
Bug introduced by
It seems like $romn can also be of type Gedcom\Record\Indi\Name; however, parameter $item of FamilyTree365\LaravelGed...\Indi\Name\Romn::read() does only seem to accept Gedcom\Record\Indi\Name\Romn, 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

84
            \FamilyTree365\LaravelGedcom\Utils\Importer\Indi\Name\Romn::read($conn, /** @scrutinizer ignore-type */ $romn, $_group, $_gid);
Loading history...
85
        }
86
    }
87
}
88