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

Slgs::read()   B

Complexity

Conditions 11
Paths 37

Size

Total Lines 53
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 33
nc 37
nop 3
dl 0
loc 53
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\Fam;
4
5
use FamilyTree365\LaravelGedcom\Models\FamilySlgs;
6
use Throwable;
7
8
class Slgs
9
{
10
    /**
11
     * Array of persons ID
12
     * key - old GEDCOM ID
13
     * value - new autoincrement ID.
14
     *
15
     * @var string
16
     */
17
    public static function read($conn, $slgs, $fam)
18
    {
19
        try
20
        {
21
            if ($slgs == null || $fam === null) {
22
                return;
23
            }
24
25
            $stat = $slgs->getStat();
26
            $date = $slgs->getDate();
27
            $plac = $slgs->getPlac();
28
            $temp = $slgs->getTemp();
29
30
            $key = [
31
                'family_id'=> $fam->id,
32
                'stat'     => $stat,
33
                'date'     => $date,
34
                'plac'     => $plac,
35
                'temp'     => $temp,
36
            ];
37
            $data = [
38
                'family_id'=> $fam->id,
39
                'stat'     => $stat,
40
                'date'     => $date,
41
                'plac'     => $plac,
42
                'temp'     => $temp,
43
            ];
44
45
            $record = FamilySlgs::on($conn)->updateOrCreate($key, $data);
46
47
            $_group = 'fam_slgs';
48
            $_gid = $record->id;
49
50
            // array
51
            $sour = $slgs->getSour();
52
            if ($sour && count($sour) > 0) {
53
                foreach ($sour as $item) {
54
                    if ($item) {
55
                        \FamilyTree365\LaravelGedcom\Utils\Importer\SourRef::read($conn, $item, $_group, $_gid);
56
                    }
57
                }
58
            }
59
60
            $note = $slgs->getNote();
61
            if ($note && count($note) > 0) {
62
                foreach ($note as $item) {
63
                    \FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef::read($conn, $item, $_group, $_gid);
64
                }
65
            }
66
        }
67
        catch(Throwable $e)
68
        {
69
            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

69
            /** @scrutinizer ignore-call */ 
70
            report($e);
Loading history...
70
        }
71
    }
72
}
73