Even   A
last analyzed

Complexity

Total Complexity 32

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 113
dl 0
loc 152
rs 9.84
c 0
b 0
f 0
wmc 32

1 Method

Rating   Name   Duplication   Size   Complexity  
F read() 0 143 32
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Exporter\Fam;
4
5
use FamilyTree365\LaravelGedcom\Models\FamilyEvent;
6
use Throwable;
7
8
class Even
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, $even, $fam, $obje_ids = [])
18
    {
19
        try
20
        {
21
            if ($even == null || $fam === null) {
22
                return;
23
            }
24
            $class_name = get_class($even);
25
            $type = $even->getType();
26
            $_date = $even->getDate();
27
            $date = \FamilyTree365\LaravelGedcom\Utils\Importer\Date::read($conn, $_date);
28
            if (strpos($date, 'BEF') !== false) {
0 ignored issues
show
Bug introduced by
It seems like $date can also be of type null; however, parameter $haystack of strpos() does only seem to accept string, 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

28
            if (strpos(/** @scrutinizer ignore-type */ $date, 'BEF') !== false) {
Loading history...
29
                $newdate = trim(str_replace('BEF', '', $date));
30
                $date_cnvert = strtotime($newdate);
31
            } elseif (strpos($date, 'AFT') !== false) {
32
                $newdate = trim(str_replace('AFT', '', $date));
33
                $date_cnvert = strtotime($newdate);
34
            } else {
35
                $date_cnvert = strtotime($date);
0 ignored issues
show
Bug introduced by
It seems like $date can also be of type null; however, parameter $datetime of strtotime() does only seem to accept string, 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

35
                $date_cnvert = strtotime(/** @scrutinizer ignore-type */ $date);
Loading history...
36
            }
37
            $_plac = $even->getPlac();
38
            $plac = \FamilyTree365\LaravelGedcom\Utils\Importer\Indi\Even\Plac::read($conn, $_plac);
39
            $_phon = $even->getPhon();
40
            $phon = \FamilyTree365\LaravelGedcom\Utils\Importer\Phon::read($conn, $_phon);
41
            $_addr = $even->getAddr();
42
            $addr_id = \FamilyTree365\LaravelGedcom\Utils\Importer\Addr::read($conn, $_addr);
43
            $caus = $even->getCaus();
44
            $age = $even->getAge();
45
            $agnc = $even->getAgnc();
46
            $fam_id = $fam->id;
47
            $husb_id = $fam->husband_id;
48
            $wife_id = $fam->wife_id;
49
            // update husb age
50
            $_husb = $even->getHusb();
51
            if ($_husb) {
52
                $husb = Person::on($conn)->find($husb_id);
0 ignored issues
show
Bug introduced by
The type FamilyTree365\LaravelGed...ils\Exporter\Fam\Person was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
53
                if ($husb) {
54
                    $husb->age = $_husb->getAge();
55
                    $husb->save();
56
                }
57
            }
58
59
            // update wife age
60
            $_wife = $even->getWife();
61
            if ($_wife) {
62
                $wife = Person::on($conn)->find($wife_id);
63
                if ($wife) {
64
                    $wife->age = $_wife->getAge();
65
                    $wife->save();
66
                }
67
            }
68
69
            switch ($class_name) {
70
                case 'Even':
71
                break;
72
                case 'Anul':
73
                break;
74
                case 'Cens':
75
                break;
76
                case 'Div':
77
                break;
78
                case 'Divf':
79
                break;
80
                case 'Enga':
81
                break;
82
                case 'Marr':
83
                break;
84
                case 'Marb':
85
                break;
86
                case 'Marc':
87
                break;
88
                case 'Marl':
89
                break;
90
                case 'Mars':
91
                break;
92
                default:
93
            }
94
            $adop = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $adop is dead and can be removed.
Loading history...
95
            $adop_famc = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $adop_famc is dead and can be removed.
Loading history...
96
            $birt_famc = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $birt_famc is dead and can be removed.
Loading history...
97
            // store Fam/Even
98
            $key = [
99
                'family_id'      => $fam_id,
100
                'title'          => $class_name,
101
                'type'           => $type,
102
                'date'           => $date,
103
                'converted_date' => $date_cnvert,
104
                'plac'           => $plac,
105
                'phon'           => $phon,
106
                'caus'           => $caus,
107
                'age'            => $age,
108
                'agnc'           => $agnc,
109
                'husb'           => $husb_id,
110
                'wife'           => $wife_id,
111
            ];
112
            $data = [
113
                'family_id'      => $fam_id,
114
                'title'          => $class_name,
115
                'type'           => $type, //
116
                'date'           => $date,
117
                'converted_date' => $date_cnvert,
118
                'plac'           => $plac, //
119
                'addr_id'        => $addr_id, //
120
                'phon'           => $phon, //
121
                'caus'           => $caus, //
122
                'age'            => $age, //
123
                'agnc'           => $agnc, //
124
                'husb'           => $husb_id, //
125
                'wife'           => $wife_id, //
126
            ];
127
128
            $record = FamilyEvent::on($conn)->updateOrCreate($key, $data);
129
130
            $_group = 'fam_even';
131
            $_gid = $record->id;
132
133
            // array
134
            $sour = $even->getSour();
135
            if ($sour && count($sour) > 0) {
136
                foreach ($sour as $item) {
137
                    if ($item) {
138
                        \FamilyTree365\LaravelGedcom\Utils\Importer\SourRef::read($conn, $item, $_group, $_gid);
139
                    }
140
                }
141
            }
142
            $obje = $even->getObje();
143
            if ($obje && count($obje) > 0) {
144
                foreach ($obje as $item) {
145
                    if ($item) {
146
                        \FamilyTree365\LaravelGedcom\Utils\Importer\ObjeRef::read($conn, $item, $_group, $_gid, $obje_ids);
147
                    }
148
                }
149
            }
150
            $notes = $even->getNote();
151
            if ($notes && count($notes) > 0) {
152
                foreach ($notes as $item) {
153
                    \FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef::read($conn, $item, $_group, $_gid);
154
                }
155
            }
156
        }
157
        catch(Throwable $e)
158
        {
159
            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

159
            /** @scrutinizer ignore-call */ 
160
            report($e);
Loading history...
160
        }
161
    }
162
}
163