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

Asso::read()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 18
nc 8
nop 4
dl 0
loc 29
rs 8.0555
c 0
b 0
f 0
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Exporter\Indi;
4
5
use FamilyTree365\LaravelGedcom\Models\PersonAsso;
6
7
class Asso
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\Asso $asso, $group = '', $group_id = 0)
15
    {
16
        $indi = $group_id;
0 ignored issues
show
Unused Code introduced by
The assignment to $indi is dead and can be removed.
Loading history...
17
        $_indi = $asso->getIndi();
18
        $rela = $asso->getRela();
19
20
        // store asso
21
        $key = ['group'=>$group, 'gid'=>$group_id, 'rela'=>$rela, 'indi' => $_indi];
22
        $data = ['group'=>$group, 'gid'=>$group_id, 'rela'=>$rela, 'indi' => $_indi];
23
        $record = PersonAsso::on($conn)->updateOrCreate($key, $data);
24
25
        $_group = 'indi_asso';
26
        $_gid = $record->id;
27
        // store Note
28
        $note = $asso->getNote();
29
        if ($note && count($note) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $note can also be of type Gedcom\Record\Indi\Asso; 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

29
        if ($note && count(/** @scrutinizer ignore-type */ $note) > 0) {
Loading history...
30
            foreach ($note as $item) {
31
                if ($item) {
32
                    \FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef::read($conn, $item, $_group, $_gid);
33
                }
34
            }
35
        }
36
37
        // store sourref
38
        $sour = $asso->getSour();
39
        if ($sour && count($sour) > 0) {
40
            foreach ($sour as $item) {
41
                if ($item) {
42
                    \FamilyTree365\LaravelGedcom\Utils\Importer\SourRef::read($conn, $item, $_group, $_gid);
43
                }
44
            }
45
        }
46
    }
47
}
48