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

Note::read()   B

Complexity

Conditions 9
Paths 53

Size

Total Lines 41
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 22
nc 53
nop 4
dl 0
loc 41
rs 8.0555
c 0
b 0
f 0
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Exporter;
4
5
use FamilyTree365\LaravelGedcom\Models\Note as MNote;
6
use Throwable;
7
8
class Note
9
{
10
    /**
11
     * Gedcom\Record\NoteRef $noteref
12
     * String $group
13
     * Integer $group_id.
14
     */
15
    public static function read($conn, \Gedcom\Record\Note $note, $group = '', $group_id = 0)
16
    {
17
       try
18
       {
19
             $_note = $note->getNote();
20
            $rin = $note->getRin();
21
22
            // store note
23
            $key = ['group'=>$group, 'gid'=>$group_id, 'note'=> utf8_encode($_note) ];
0 ignored issues
show
Bug introduced by
It seems like $_note can also be of type Gedcom\Record\Note and null; however, parameter $string of utf8_encode() does only seem to accept string, 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

23
            $key = ['group'=>$group, 'gid'=>$group_id, 'note'=> utf8_encode(/** @scrutinizer ignore-type */ $_note) ];
Loading history...
24
            $data = ['group'=>$group, 'gid'=>$group_id, 'note'=> utf8_encode($_note), 'rin'=>$rin];
25
            $record = MNote::on($conn)->updateOrCreate($key, $data);
26
27
            // store Sources of Note
28
            $_group = 'note';
29
            $_gid = $record->id;
30
            // SourRef array
31
            $sour = $note->getSour();
32
            if ($sour && count($sour) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $sour can also be of type Gedcom\Record\Note; 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

32
            if ($sour && count(/** @scrutinizer ignore-type */ $sour) > 0) {
Loading history...
33
                foreach ($sour as $item) {
34
                    SourRef::read($conn, $item, $_group, $_gid);
35
                }
36
            }
37
            // Refn array
38
            $refn = $note->getRefn();
39
            if ($refn && count($refn) > 0) {
40
                foreach ($refn as $item) {
41
                    Refn::read($conn, $item, $_group, $_gid);
42
                }
43
            }
44
45
            // Chan
46
            $chan = $note->getChan();
47
            if ($chan !== null) {
48
                Chan::read($conn, $chan, $_group, $_gid);
0 ignored issues
show
Bug introduced by
It seems like $chan can also be of type Gedcom\Record\Note; however, parameter $chan of FamilyTree365\LaravelGed...s\Exporter\Chan::read() does only seem to accept Gedcom\Record\Chan, 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

48
                Chan::read($conn, /** @scrutinizer ignore-type */ $chan, $_group, $_gid);
Loading history...
49
            }
50
51
            return $_gid;
52
       }
53
       catch(Throwable $e)
54
       {
55
        report($e);
0 ignored issues
show
Bug introduced by
The function report was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

55
        /** @scrutinizer ignore-call */ 
56
        report($e);
Loading history...
56
       }
57
58
    }
59
}
60