| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 143 |
| Code Lines | 112 |
| 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 |
||
| 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) { |
||
|
|
|||
| 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); |
||
| 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); |
||
| 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 = ''; |
||
| 95 | $adop_famc = ''; |
||
| 96 | $birt_famc = ''; |
||
| 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); |
||
| 160 | } |
||
| 163 |