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