Conditions | 11 |
Paths | 1707 |
Total Lines | 109 |
Code Lines | 89 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 2 | Features | 1 |
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 |
||
25 | public static function getPerson($conn, $individuals, $obje_ids = [], $sour_ids = []) |
||
26 | { |
||
27 | $ParentData = []; |
||
28 | |||
29 | try { |
||
30 | foreach ($individuals as $k => $individual) { |
||
31 | $g_id = $individual->getId(); |
||
|
|||
32 | $name = ''; |
||
33 | $givn = ''; |
||
34 | $surn = ''; |
||
35 | $name = ''; |
||
36 | $npfx = ''; |
||
37 | $givn = ''; |
||
38 | $nick = ''; |
||
39 | $spfx = ''; |
||
40 | $surn = ''; |
||
41 | $nsfx = ''; |
||
42 | $type = ''; |
||
43 | $fone = null; // Gedcom/ |
||
44 | $romn = null; |
||
45 | $names = $individual->getName(); |
||
46 | $attr = $individual->getAllAttr(); |
||
47 | $events = $individual->getAllEven(); |
||
48 | $note = $individual->getNote(); |
||
49 | $indv_sour = $individual->getSour(); |
||
50 | $alia = $individual->getAlia(); // string array |
||
51 | $asso = $individual->getAsso(); |
||
52 | $subm = $individual->getSubm(); |
||
53 | $anci = $individual->getAnci(); |
||
54 | $refn = $individual->getRefn(); |
||
55 | $obje = $individual->getObje(); |
||
56 | // object |
||
57 | $bapl = $individual->getBapl(); |
||
58 | $conl = $individual->getConl(); |
||
59 | $endl = $individual->getEndl(); |
||
60 | $slgc = $individual->getSlgc(); |
||
61 | $chan = $individual->getChan(); |
||
62 | $g_id = $individual->getId(); |
||
63 | |||
64 | if (!empty($names)) { |
||
65 | $name = current($names)->getName(); |
||
66 | $npfx = current($names)->getNpfx(); |
||
67 | $givn = current($names)->getGivn(); |
||
68 | $nick = current($names)->getNick(); |
||
69 | $spfx = current($names)->getSpfx(); |
||
70 | $surn = current($names)->getSurn(); |
||
71 | $nsfx = current($names)->getNsfx(); |
||
72 | $type = current($names)->getType(); |
||
73 | } |
||
74 | |||
75 | // array value |
||
76 | $fams = $individual->getFams(); // self family, leave it now, note would be included in family |
||
77 | $famc = $individual->getFamc(); // parent family , leave it now, note and pedi would be included in family |
||
78 | |||
79 | // added to database |
||
80 | // string value |
||
81 | $sex = preg_replace('/[^MF]/', '', $individual->getSex()); |
||
82 | $uid = $individual->getUid(); |
||
83 | $resn = $individual->getResn(); |
||
84 | $rin = $individual->getRin(); |
||
85 | $rfn = $individual->getRfn(); |
||
86 | $afn = $individual->getAfn(); |
||
87 | $birthday = strlen($individual->getBirthday()) > 4 ? $individual->getBirthday() : null; |
||
88 | $birth_year = strlen($individual->getBirthday()) === 4 ? $individual->getBirthday() : null; |
||
89 | $deathday = strlen($individual->getDeathday()) > 4 ? $individual->getDeathday() : null; |
||
90 | $death_year = strlen($individual->getDeathday()) === 4 ? $individual->getDeathday() : null; |
||
91 | $burial_day = strlen($individual->getBurialday()) > 4 ? $individual->getBurialday() : null; |
||
92 | $burial_year = strlen($individual->getBurialday()) === 4 ? $individual->getBurialday() : null; |
||
93 | |||
94 | if ($givn == '') { |
||
95 | $givn = $name; |
||
96 | } |
||
97 | |||
98 | $config = json_encode(config('database.connections.'.$conn)); |
||
99 | $value = [ |
||
100 | 'gid' => $g_id, |
||
101 | 'name' => $name, |
||
102 | 'givn' => $givn, |
||
103 | 'surn' => $surn, |
||
104 | 'sex' => $sex, |
||
105 | 'uid' => $uid, |
||
106 | 'rin' => $rin, |
||
107 | 'resn' => $resn, |
||
108 | 'rfn' => $rfn, |
||
109 | 'afn' => $afn, |
||
110 | 'birthday' => $birthday, |
||
111 | 'birth_year' => $birth_year, |
||
112 | 'deathday' => $deathday, |
||
113 | 'death_year' => $death_year, |
||
114 | 'burial_day' => $burial_day, |
||
115 | 'burial_year' => $burial_year, |
||
116 | 'nick' => $nick, |
||
117 | 'type' => $type, |
||
118 | 'chan' => $chan->getDatetime(), |
||
119 | 'nsfx' => $nsfx, |
||
120 | 'npfx' => $npfx, |
||
121 | 'spfx' => $spfx |
||
122 | ]; |
||
123 | |||
124 | $ParentData[] = $value; |
||
125 | } |
||
126 | |||
127 | // it's take only 1 second for 3010 record |
||
128 | Person::on($conn)->insert($ParentData); |
||
129 | otherFields::insertOtherFields($conn, $individuals, $obje_ids, $sour_ids); |
||
130 | } catch (\Exception $e) { |
||
131 | $error = $e->getMessage(); |
||
132 | |||
133 | return \Log::error($error); |
||
134 | } |
||
137 |