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

SourRef   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 11

1 Method

Rating   Name   Duplication   Size   Complexity  
B read() 0 55 11
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Exporter;
4
5
use FamilyTree365\LaravelGedcom\Models\SourceRef;
6
use FamilyTree365\LaravelGedcom\Utils\Importer\Sour\Data;
7
use FamilyTree365\LaravelGedcom\Utils\Importer\SourRef\Even;
8
9
class SourRef
10
{
11
    /**
12
     * Gedcom\Record\SourRef $sourref
13
     * String $group
14
     * Integer $group_id.
15
     */
16
    public static function read($conn, \Gedcom\Record\SourRef $sourref, $group = '', $group_id = 0, $sour_ids = [], $obje_ids = [])
17
    {
18
        if ($sourref == null) {
19
            return;
20
        }
21
22
        $sour = $sourref->getSour();
23
        if (!isset($sour_ids[$sour])) {
24
            return;
25
        }
26
        $sour_id = $sour_ids[$sour];
27
        $text = $sourref->getText();
28
        $quay = $sourref->getQuay();
29
        $page = $sourref->getPage();
30
31
        // store Source
32
        $key = ['group'=>$group, 'gid'=>$group_id, 'sour_id'=>$sour_id];
33
        $data = [
34
            'group'  => $group,
35
            'gid'    => $group_id,
36
            'sour_id'=> $sour_id,
37
            'text'   => $text,
38
            'quay'   => $quay,
39
            'page'   => $page,
40
        ];
41
        $record = SourceRef::on($conn)->updateOrCreate($key, $data);
42
43
        $_group = 'sourref';
44
        $_gid = $record->id;
45
        // store MediaObje
46
        $objes = $sourref->getObje();
47
        if ($objes && count($objes) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $objes can also be of type Gedcom\Record\SourRef; 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

47
        if ($objes && count(/** @scrutinizer ignore-type */ $objes) > 0) {
Loading history...
48
            foreach ($objes as $item) {
49
                ObjeRef::read($conn, $item, $_group, $_gid, $obje_ids);
50
            }
51
        }
52
53
        // store Note
54
        $notes = $sourref->getNote();
55
        if ($notes && count($notes) > 0) {
56
            foreach ($notes as $item) {
57
                NoteRef::read($conn, $item, $_group, $_gid);
58
            }
59
        }
60
61
        // store Data
62
        $data = $sourref->getData();
63
        if ($data) {
64
            Data::read($conn, $data, $_group, $_gid);
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type Gedcom\Record\SourRef; however, parameter $data of FamilyTree365\LaravelGed...orter\Sour\Data::read() does only seem to accept Gedcom\Record\Sour\Data, 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

64
            Data::read($conn, /** @scrutinizer ignore-type */ $data, $_group, $_gid);
Loading history...
65
        }
66
67
        // store \Gedcom\Record\SourRef\Even
68
        $even = $sourref->getEven();
69
        if ($even) {
70
            Even::read($conn, $even, $_group, $_gid);
0 ignored issues
show
Bug introduced by
It seems like $even can also be of type Gedcom\Record\SourRef; however, parameter $even of FamilyTree365\LaravelGed...er\SourRef\Even::read() does only seem to accept Gedcom\Record\SourRef\Even, 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

70
            Even::read($conn, /** @scrutinizer ignore-type */ $even, $_group, $_gid);
Loading history...
71
        }
72
    }
73
}
74