| Conditions | 8 |
| Paths | 40 |
| Total Lines | 93 |
| Code Lines | 67 |
| 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 |
||
| 50 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 51 | { |
||
| 52 | $tree = Validator::attributes($request)->tree(); |
||
| 53 | $params = (array) $request->getParsedBody(); |
||
| 54 | |||
| 55 | // For backwards compatibility with webtrees 1.x we store the two calendar formats in one variable |
||
| 56 | // e.g. "gregorian_and_jewish" |
||
| 57 | $tree->setPreference('CALENDAR_FORMAT', implode('_and_', array_unique([ |
||
| 58 | $params['CALENDAR_FORMAT0'] ?? 'none', |
||
| 59 | $params['CALENDAR_FORMAT1'] ?? 'none', |
||
| 60 | ]))); |
||
| 61 | $tree->setPreference('CHART_BOX_TAGS', implode(',', $params['CHART_BOX_TAGS'] ?? [])); |
||
| 62 | $tree->setPreference('CONTACT_USER_ID', $params['CONTACT_USER_ID'] ?? ''); |
||
| 63 | $tree->setPreference('EXPAND_NOTES', $params['EXPAND_NOTES'] ?? ''); |
||
| 64 | $tree->setPreference('EXPAND_SOURCES', $params['EXPAND_SOURCES'] ?? ''); |
||
| 65 | $tree->setPreference('FAM_FACTS_QUICK', implode(',', $params['FAM_FACTS_QUICK'] ?? [])); |
||
| 66 | $tree->setPreference('FULL_SOURCES', $params['FULL_SOURCES'] ?? ''); |
||
| 67 | $tree->setPreference('FORMAT_TEXT', $params['FORMAT_TEXT'] ?? ''); |
||
| 68 | $tree->setPreference('GENERATE_UIDS', $params['GENERATE_UIDS'] ?? ''); |
||
| 69 | $tree->setPreference('HIDE_GEDCOM_ERRORS', $params['HIDE_GEDCOM_ERRORS'] ?? ''); |
||
| 70 | $tree->setPreference('INDI_FACTS_QUICK', implode(',', $params['INDI_FACTS_QUICK'] ?? [])); |
||
| 71 | $tree->setPreference('MEDIA_UPLOAD', $params['MEDIA_UPLOAD'] ?? ''); |
||
| 72 | $tree->setPreference('META_DESCRIPTION', $params['META_DESCRIPTION'] ?? ''); |
||
| 73 | $tree->setPreference('META_TITLE', $params['META_TITLE'] ?? ''); |
||
| 74 | $tree->setPreference('NO_UPDATE_CHAN', $params['NO_UPDATE_CHAN'] ?? ''); |
||
| 75 | $tree->setPreference('PEDIGREE_ROOT_ID', $params['PEDIGREE_ROOT_ID'] ?? ''); |
||
| 76 | $tree->setPreference('PREFER_LEVEL2_SOURCES', $params['PREFER_LEVEL2_SOURCES'] ?? ''); |
||
| 77 | $tree->setPreference('QUICK_REQUIRED_FACTS', implode(',', $params['QUICK_REQUIRED_FACTS'] ?? [])); |
||
| 78 | $tree->setPreference('QUICK_REQUIRED_FAMFACTS', implode(',', $params['QUICK_REQUIRED_FAMFACTS'] ?? [])); |
||
| 79 | $tree->setPreference('SHOW_COUNTER', $params['SHOW_COUNTER'] ?? ''); |
||
| 80 | $tree->setPreference('SHOW_EST_LIST_DATES', $params['SHOW_EST_LIST_DATES'] ?? ''); |
||
| 81 | $tree->setPreference('SHOW_FACT_ICONS', $params['SHOW_FACT_ICONS'] ?? ''); |
||
| 82 | $tree->setPreference('SHOW_GEDCOM_RECORD', $params['SHOW_GEDCOM_RECORD'] ?? ''); |
||
| 83 | $tree->setPreference('SHOW_HIGHLIGHT_IMAGES', $params['SHOW_HIGHLIGHT_IMAGES'] ?? ''); |
||
| 84 | $tree->setPreference('SHOW_LAST_CHANGE', $params['SHOW_LAST_CHANGE'] ?? ''); |
||
| 85 | $tree->setPreference('SHOW_MEDIA_DOWNLOAD', $params['SHOW_MEDIA_DOWNLOAD'] ?? ''); |
||
| 86 | $tree->setPreference('SHOW_NO_WATERMARK', $params['SHOW_NO_WATERMARK'] ?? ''); |
||
| 87 | $tree->setPreference('SHOW_PARENTS_AGE', $params['SHOW_PARENTS_AGE'] ?? ''); |
||
| 88 | $tree->setPreference('SHOW_PEDIGREE_PLACES', $params['SHOW_PEDIGREE_PLACES'] ?? ''); |
||
| 89 | $tree->setPreference('SHOW_PEDIGREE_PLACES_SUFFIX', $params['SHOW_PEDIGREE_PLACES_SUFFIX'] ?? ''); |
||
| 90 | $tree->setPreference('SHOW_RELATIVES_EVENTS', implode(',', $params['SHOW_RELATIVES_EVENTS'] ?? [])); |
||
| 91 | $tree->setPreference('SUBLIST_TRIGGER_I', $params['SUBLIST_TRIGGER_I'] ?? '200'); |
||
| 92 | $tree->setPreference('SURNAME_LIST_STYLE', $params['SURNAME_LIST_STYLE'] ?? ''); |
||
| 93 | $tree->setPreference('SURNAME_TRADITION', $params['SURNAME_TRADITION'] ?? ''); |
||
| 94 | $tree->setPreference('USE_SILHOUETTE', $params['USE_SILHOUETTE'] ?? ''); |
||
| 95 | $tree->setPreference('WEBMASTER_USER_ID', $params['WEBMASTER_USER_ID'] ?? ''); |
||
| 96 | $tree->setPreference('title', $params['title'] ?? ''); |
||
| 97 | |||
| 98 | if (Auth::isAdmin()) { |
||
| 99 | // Only accept valid folders for MEDIA_DIRECTORY |
||
| 100 | $MEDIA_DIRECTORY = $params['MEDIA_DIRECTORY'] ?? ''; |
||
| 101 | $MEDIA_DIRECTORY = preg_replace('/[:\/\\\\]+/', '/', $MEDIA_DIRECTORY); |
||
| 102 | $MEDIA_DIRECTORY = trim($MEDIA_DIRECTORY, '/') . '/'; |
||
| 103 | |||
| 104 | $tree->setPreference('MEDIA_DIRECTORY', $MEDIA_DIRECTORY); |
||
| 105 | } |
||
| 106 | |||
| 107 | $gedcom = $params['gedcom'] ?? ''; |
||
| 108 | $url = route(ManageTrees::class, ['tree' => $tree->name()]); |
||
| 109 | |||
| 110 | if (Auth::isAdmin() && $gedcom !== '' && $gedcom !== $tree->name()) { |
||
| 111 | try { |
||
| 112 | DB::table('gedcom') |
||
| 113 | ->where('gedcom_id', '=', $tree->id()) |
||
| 114 | ->update(['gedcom_name' => $gedcom]); |
||
| 115 | |||
| 116 | // Did we rename the default tree? |
||
| 117 | DB::table('site_setting') |
||
| 118 | ->where('setting_name', '=', 'DEFAULT_GEDCOM') |
||
| 119 | ->where('setting_value', '=', $tree->name()) |
||
| 120 | ->update(['setting_value' => $gedcom]); |
||
| 121 | |||
| 122 | $url = route(ManageTrees::class, ['tree' => $gedcom]); |
||
| 123 | } catch (PDOException $ex) { |
||
| 124 | // Probably a duplicate name. |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | FlashMessages::addMessage(I18N::translate('The preferences for the family tree ā%sā have been updated.', e($tree->title())), 'success'); |
||
| 129 | |||
| 130 | // Coming soon... |
||
| 131 | $all_trees = $params['all_trees'] ?? ''; |
||
| 132 | $new_trees = $params['new_trees'] ?? ''; |
||
| 133 | |||
| 134 | if ($all_trees === 'on') { |
||
| 135 | FlashMessages::addMessage(I18N::translate('The preferences for all family trees have been updated.'), 'success'); |
||
| 136 | } |
||
| 137 | |||
| 138 | if ($new_trees === 'on') { |
||
| 139 | FlashMessages::addMessage(I18N::translate('The preferences for new family trees have been updated.'), 'success'); |
||
| 140 | } |
||
| 141 | |||
| 142 | return redirect($url); |
||
| 143 | } |
||
| 145 |