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

Obje::read()   C

Complexity

Conditions 13
Paths 17

Size

Total Lines 57
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 33
nc 17
nop 4
dl 0
loc 57
rs 6.6166
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\MediaObject;
6
7
class Obje
8
{
9
    /**
10
     * Gedcom\Record\Obje $obje
11
     * String $group
12
     * Integer $group_id.
13
     */
14
    public static function read($conn, \Gedcom\Record\Obje $obje, $group = '', $group_id = 0)
15
    {
16
        if ($obje == null) {
17
            return 0;
18
        }
19
20
        $id = $obje->getId();
21
        $rin = $obje->getRin(); // string
22
23
        // store Object
24
        $key = [
25
            'group'   => $group,
26
            'gid'     => $group_id,
27
            'rin'     => $rin,
28
            'obje_id' => $id,
29
        ];
30
        $data = [
31
            'group'   => $group,
32
            'gid'     => $group_id,
33
            'rin'     => $rin,
34
            'obje_id' => $id,
35
        ];
36
37
        $record = MediaObject::on($conn)->updateOrCreate($key, $data);
38
39
        $_group = 'obje';
40
        $_gid = $record->id;
41
42
        $refn = $obje->getRefn(); // Record/Refn array
43
        if ($refn && count($refn) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $refn can also be of type Gedcom\Record\Obje; 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

43
        if ($refn && count(/** @scrutinizer ignore-type */ $refn) > 0) {
Loading history...
44
            foreach ($refn as $item) {
45
                Refn::read($conn, $item, $_group, $_gid);
46
            }
47
        }
48
49
        // store Note
50
        $note = $obje->getNote(); // Record/NoteRef array
51
        if ($note && count($note) > 0) {
52
            foreach ($note as $item) {
53
                NoteRef::read($conn, $item, $_group, $_gid);
54
            }
55
        }
56
57
        // store Note
58
        $files = $obje->getFile(); // Record/NoteRef array
59
        if (($files && count((is_countable($files) ? $files : [])))) {
60
            foreach ($files as $item) {
61
                \FamilyTree365\LaravelGedcom\Utils\Importer\ObjeRef\File::read($conn, $item, $_group, $_gid);
62
            }
63
        }
64
65
        $chan = $obje->getChan(); // Recore/Chan
66
        if ($chan !== null) {
67
            \FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, $chan, $_group, $_gid);
0 ignored issues
show
Bug introduced by
It seems like $chan can also be of type Gedcom\Record\Obje; however, parameter $chan of FamilyTree365\LaravelGed...s\Importer\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

67
            \FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, /** @scrutinizer ignore-type */ $chan, $_group, $_gid);
Loading history...
68
        }
69
70
        return $_gid;
71
    }
72
}
73