Data::read()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 16
nc 6
nop 4
dl 0
loc 25
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Importer\Sour;
4
5
use FamilyTree365\LaravelGedcom\Models\SourceData;
6
use FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef;
7
use FamilyTree365\LaravelGedcom\Utils\Importer\Sour\Data\Even;
8
9
class Data
10
{
11
    /**
12
     * Gedcom\Record\Sour\Data $data
13
     * String $group
14
     * Integer $group_id.
15
     */
16
    public static function read($conn, \Gedcom\Record\Sour\Data $data, $group = '', $group_id = 0)
17
    {
18
        $date = $data->getDate();
19
        $agnc = $data->getAgnc();
20
        $text = $data->getText();
21
22
        // store Data of sources
23
        $key = ['group'=>$group, 'gid'=>$group_id, 'date'=>$date, 'text'=>$text, 'agnc'=>$agnc];
24
        $_data = ['group'=>$group, 'gid'=>$group_id, 'date'=>$date, 'text'=>$text, 'agnc'=>$agnc];
25
        $record = SourceData::on($conn)->updateOrCreate($key, $_data);
26
27
        $_group = 'sourcedata';
28
        $_gid = $record->id;
29
        // \Gedcom\Record\Sour\Data\Even array
30
        $even = $data->getEven();
31
        if ($even && count($even) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $even can also be of type Gedcom\Record\Sour\Data; 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

31
        if ($even && count(/** @scrutinizer ignore-type */ $even) > 0) {
Loading history...
32
            foreach ($even as $item) {
33
                Even::read($conn, $item, $_group, $_gid);
34
            }
35
        }
36
        // \Gedcom\Record\NoteRef array
37
        $note = $data->getNote();
38
        if ($note && count($note) > 0) {
39
            foreach ($note as $item) {
40
                NoteRef::read($conn, $item, $_group, $_gid);
41
            }
42
        }
43
    }
44
}
45