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

SourRef::read()   B

Complexity

Conditions 11
Paths 18

Size

Total Lines 55
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 34
nc 18
nop 6
dl 0
loc 55
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;
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