| Conditions | 9 |
| Paths | 9 |
| Total Lines | 65 |
| Code Lines | 49 |
| 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, \Gedcom\Record\Repo $repo, $group = '', $group_id = 0) |
||
| 15 | { |
||
| 16 | if ($repo == null) { |
||
| 17 | return; |
||
| 18 | } |
||
| 19 | $name = $repo->getName(); // string |
||
| 20 | $rin = $repo->getRin(); // string |
||
| 21 | $addr = $repo->getAddr(); // Record/Addr |
||
| 22 | $addr_id = \FamilyTree365\LaravelGedcom\Utils\Importer\Addr::read($conn, $addr); |
||
| 23 | $_phon = $repo->getPhon(); // Record/Phon array |
||
| 24 | $phon = implode(',', $_phon); |
||
| 25 | $_email = $repo->getEmail(); |
||
| 26 | $email = implode(',', $_email); |
||
| 27 | $_fax = $repo->getFax(); |
||
| 28 | $fax = implode(',', $_fax); |
||
| 29 | $_www = $repo->getWww(); |
||
| 30 | $www = implode(',', $_www); |
||
| 31 | // store Source |
||
| 32 | $key = [ |
||
| 33 | 'group' => $group, |
||
| 34 | 'gid' => $group_id, |
||
| 35 | 'name' => $name, |
||
| 36 | 'rin' => $rin, |
||
| 37 | 'addr_id' => $addr_id, |
||
| 38 | 'phon' => $phon, |
||
| 39 | 'email' => $email, |
||
| 40 | 'fax' => $fax, |
||
| 41 | 'www' => $www, |
||
| 42 | ]; |
||
| 43 | $data = [ |
||
| 44 | 'group' => $group, |
||
| 45 | 'gid' => $group_id, |
||
| 46 | 'name' => $name, |
||
| 47 | 'rin' => $rin, |
||
| 48 | 'addr_id' => $addr_id, |
||
| 49 | 'phon' => $phon, |
||
| 50 | 'email' => $email, |
||
| 51 | 'fax' => $fax, |
||
| 52 | 'www' => $www, |
||
| 53 | ]; |
||
| 54 | |||
| 55 | $record = Repository::on($conn)->updateOrCreate($key, $data); |
||
| 56 | |||
| 57 | $_group = 'repo'; |
||
| 58 | $_gid = $record->id; |
||
| 59 | // store Note |
||
| 60 | $note = $repo->getNote(); // Record/NoteRef array |
||
| 61 | if ($note && count($note) > 0) { |
||
|
|
|||
| 62 | foreach ($note as $item) { |
||
| 63 | NoteRef::read($conn, $item, $_group, $_gid); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | $refn = $repo->getRefn(); // Record/Refn array |
||
| 67 | if ($refn && count($refn) > 0) { |
||
| 68 | foreach ($refn as $item) { |
||
| 69 | Refn::read($conn, $item, $_group, $_gid); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $chan = $repo->getChan(); // Recore/Chan |
||
| 74 | if ($chan !== null) { |
||
| 75 | \FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, $chan, $_group, $_gid); |
||
| 76 | } |
||
| 77 | |||
| 78 | return $_gid; |
||
| 79 | } |
||
| 81 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.