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

Repo::read()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 65
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 49
nc 9
nop 4
dl 0
loc 65
rs 7.5571
c 0
b 0
f 0

How to fix   Long Method   

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\Repository;
6
7
class Repo
8
{
9
    /**
10
     * Gedcom\Record\Repo $repo
11
     * String $group
12
     * Integer $group_id.
13
     */
14
    public static function read($conn, \Gedcom\Record\Repo $repo, $group = '', $group_id = 0)
15
    {
16
        if ($repo == null) {
17
            return;
18
        }
19
        $name = $repo->getName(); // string
20
        $rin = $repo->getRin(); // string
21
        $addr = $repo->getAddr(); // Record/Addr
22
        $addr_id = \FamilyTree365\LaravelGedcom\Utils\Importer\Addr::read($conn, $addr);
23
        $_phon = $repo->getPhon(); // Record/Phon array
24
        $phon = implode(',', $_phon);
25
        $_email = $repo->getEmail();
26
        $email = implode(',', $_email);
27
        $_fax = $repo->getFax();
28
        $fax = implode(',', $_fax);
29
        $_www = $repo->getWww();
30
        $www = implode(',', $_www);
31
        // store Source
32
        $key = [
33
            'group'   => $group,
34
            'gid'     => $group_id,
35
            'name'    => $name,
36
            'rin'     => $rin,
37
            'addr_id' => $addr_id,
38
            'phon'    => $phon,
39
            'email'   => $email,
40
            'fax'     => $fax,
41
            'www'     => $www,
42
        ];
43
        $data = [
44
            'group'   => $group,
45
            'gid'     => $group_id,
46
            'name'    => $name,
47
            'rin'     => $rin,
48
            'addr_id' => $addr_id,
49
            'phon'    => $phon,
50
            'email'   => $email,
51
            'fax'     => $fax,
52
            'www'     => $www,
53
        ];
54
55
        $record = Repository::on($conn)->updateOrCreate($key, $data);
56
57
        $_group = 'repo';
58
        $_gid = $record->id;
59
        // store Note
60
        $note = $repo->getNote(); // Record/NoteRef array
61
        if ($note && count($note) > 0) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $note of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
62
            foreach ($note as $item) {
63
                NoteRef::read($conn, $item, $_group, $_gid);
64
            }
65
        }
66
        $refn = $repo->getRefn(); // Record/Refn array
67
        if ($refn && count($refn) > 0) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $refn of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
68
            foreach ($refn as $item) {
69
                Refn::read($conn, $item, $_group, $_gid);
70
            }
71
        }
72
73
        $chan = $repo->getChan(); // Recore/Chan
74
        if ($chan !== null) {
75
            \FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, $chan, $_group, $_gid);
76
        }
77
78
        return $_gid;
79
    }
80
}
81