Sour::read()   C
last analyzed

Complexity

Conditions 17
Paths 65

Size

Total Lines 60
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 38
nc 65
nop 3
dl 0
loc 60
rs 5.2166
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\Importer;
4
5
use FamilyTree365\LaravelGedcom\Models\Source;
6
7
class Sour
8
{
9
    /**
10
     * Gedcom\Record\Subn $subn
11
     * String $group
12
     * Integer $group_id.
13
     */
14
    public static function read($conn, $sour, $obje_ids = [])
15
    {
16
        if ($sour == null || is_array($sour)) {
17
            return 0;
18
        }
19
        $auth = $sour->getAuth(); // string
20
        $titl = $sour->getTitl(); // string
21
        $abbr = $sour->getAbbr(); // string
22
        $publ = $sour->getPubl(); // string
23
        $rin = $sour->getRin(); // string
24
        $text = $sour->getText(); // string
25
26
        $record = Source::on($conn)->updateOrCreate(
27
            compact('titl', 'rin', 'auth', 'text', 'publ', 'abbr'),
28
            compact('titl', 'rin', 'auth', 'text', 'publ', 'abbr')
29
        );
30
31
        $_group = 'sour';
32
        $_gid = $record->id;
33
34
        $chan = $sour->getChan(); // Record/Chan
35
        if ($chan !== null) {
36
            \FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, $chan, $_group, $_gid = 0);
37
        }
38
        $repo = $sour->getRepo(); // Repo
39
        if ($repo !== null) {
40
            \FamilyTree365\LaravelGedcom\Utils\Importer\Sour\Repo::read($conn, $repo, $_group, $_gid = 0);
41
        }
42
        $data = $sour->getData(); // object
43
        if ($data !== null) {
44
            \FamilyTree365\LaravelGedcom\Utils\Importer\Sour\Data::read($conn, $data, $_group, $_gid = 0);
45
        }
46
        $refn = $sour->getRefn(); // array
47
        if ($refn && count($refn) > 0) {
48
            foreach ($refn as $item) {
49
                if ($item) {
50
                    \FamilyTree365\LaravelGedcom\Utils\Importer\Refn::read($conn, $item, $_group, $_gid = 0);
51
                }
52
            }
53
        }
54
55
        $note = $sour->getNote(); // array
56
        if ($note != null && count($note) > 0) {
57
            foreach ($note as $item) {
58
                \FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef::read($conn, $item, $_group, $_gid);
59
            }
60
        }
61
62
        $obje = $sour->getObje(); // array
63
        if ($obje && count($obje) > 0) {
64
            foreach ($obje as $item) {
65
                if ($item) {
66
                    \FamilyTree365\LaravelGedcom\Utils\Importer\ObjeRef::read($conn, $item, $_group, $_gid, $obje_ids);
67
                }
68
            }
69
        }
70
71
        $sour = $sour->getSour(); // string id
0 ignored issues
show
Unused Code introduced by
The assignment to $sour is dead and can be removed.
Loading history...
72
73
        return $_gid;
74
    }
75
}
76