Conditions | 12 |
Paths | 17 |
Total Lines | 77 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
14 | public static function read($conn, $subm, $group = null, $gid = null, $obje_ids = []) |
||
15 | { |
||
16 | if ($subm == null || is_array($subm)) { |
||
17 | return; |
||
18 | } |
||
19 | |||
20 | $name = $subm->getName() ?? null; // string |
||
21 | if (!is_object($subm)) { |
||
22 | $name = $subm; |
||
23 | } |
||
24 | $addr = $subm->getAddr() ?? null; |
||
25 | $addr_id = \FamilyTree365\LaravelGedcom\Utils\Importer\Addr::read($conn, $addr); |
||
26 | $_phon = $subm->getPhon() ?? []; // array |
||
27 | $phon = implode(',', $_phon); |
||
28 | $_email = $subm->getEmail() ?? []; |
||
29 | $email = implode(',', $_email); |
||
30 | $_fax = $subm->getFax() ?? []; |
||
31 | $fax = implode(',', $_fax); |
||
32 | $_www = $subm->getWww() ?? []; |
||
33 | $www = implode(',', $_www); |
||
34 | |||
35 | $rin = $subm->getRin() ?? null; // string |
||
36 | $rfn = $subm->getRfn() ?? null; // string |
||
37 | |||
38 | $_lang = $subm->getLang(); // string array |
||
39 | $lang = implode(',', $_lang); |
||
40 | $key = [ |
||
41 | 'group' => $group, |
||
42 | 'gid' => $gid, |
||
43 | 'name' => $name, |
||
44 | 'addr_id' => $addr_id, |
||
45 | 'lang' => $lang, |
||
46 | 'phon' => $phon, |
||
47 | 'email' => $email, |
||
48 | 'fax' => $fax, |
||
49 | 'www' => $www, |
||
50 | 'rin' => $rin, |
||
51 | 'rfn' => $rfn, |
||
52 | ]; |
||
53 | $data = [ |
||
54 | 'group' => $group, |
||
55 | 'gid' => $gid, |
||
56 | 'name' => $name, |
||
57 | 'addr_id' => $addr_id, |
||
58 | 'lang' => $lang, |
||
59 | 'phon' => $phon, |
||
60 | 'email' => $email, |
||
61 | 'fax' => $fax, |
||
62 | 'www' => $www, |
||
63 | 'rin' => $rin, |
||
64 | 'rfn' => $rfn, |
||
65 | ]; |
||
66 | $record = MSubm::on($conn)->updateOrCreate($key, $data); |
||
67 | $_group = 'subm'; |
||
68 | $_gid = $record->id; |
||
69 | |||
70 | $note = $subm->getNote(); // array --- |
||
71 | |||
72 | if ($note != null && count($note) > 0) { |
||
73 | foreach ($note as $item) { |
||
74 | \FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef::read($conn, $item, $_group, $_gid); |
||
75 | } |
||
76 | } |
||
77 | $obje = $subm->getObje() ?? null; // array --- |
||
78 | if ($obje && count($obje) > 0) { |
||
79 | foreach ($obje as $item) { |
||
80 | if ($item) { |
||
81 | \FamilyTree365\LaravelGedcom\Utils\Importer\ObjeRef::read($conn, $item, $_group, $_gid, $obje_ids); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | $chan = $subm->getChan() ?? null; // Record\Chan--- |
||
86 | if ($chan !== null) { |
||
87 | \FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, $chan, $_group, $_gid); |
||
88 | } |
||
89 | |||
90 | return $_gid; |
||
91 | } |
||
93 |