| Conditions | 14 |
| Paths | 68 |
| Total Lines | 80 |
| Code Lines | 53 |
| 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 |
||
| 94 | public function treePrivacyUpdate(ServerRequestInterface $request): ResponseInterface |
||
| 95 | { |
||
| 96 | $tree = $request->getAttribute('tree'); |
||
| 97 | assert($tree instanceof Tree); |
||
| 98 | |||
| 99 | $params = $request->getParsedBody(); |
||
| 100 | |||
| 101 | $delete_default_resn_id = $params['delete'] ?? []; |
||
| 102 | |||
| 103 | DB::table('default_resn') |
||
| 104 | ->whereIn('default_resn_id', $delete_default_resn_id) |
||
| 105 | ->delete(); |
||
| 106 | |||
| 107 | $xrefs = $params['xref'] ?? []; |
||
| 108 | $tag_types = $params['tag_type'] ?? []; |
||
| 109 | $resns = $params['resn'] ?? []; |
||
| 110 | |||
| 111 | foreach ($xrefs as $n => $xref) { |
||
| 112 | $tag_type = $tag_types[$n]; |
||
| 113 | $resn = $resns[$n]; |
||
| 114 | |||
| 115 | // Delete any existing data |
||
| 116 | if ($tag_type !== '' && $xref !== '') { |
||
| 117 | DB::table('default_resn') |
||
| 118 | ->where('gedcom_id', '=', $tree->id()) |
||
| 119 | ->where('tag_type', '=', $tag_type) |
||
| 120 | ->where('xref', '=', $xref) |
||
| 121 | ->delete(); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($tag_type !== '' && $xref === '') { |
||
| 125 | DB::table('default_resn') |
||
| 126 | ->where('gedcom_id', '=', $tree->id()) |
||
| 127 | ->where('tag_type', '=', $tag_type) |
||
| 128 | ->whereNull('xref') |
||
| 129 | ->delete(); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($tag_type === '' && $xref !== '') { |
||
| 133 | DB::table('default_resn') |
||
| 134 | ->where('gedcom_id', '=', $tree->id()) |
||
| 135 | ->whereNull('tag_type') |
||
| 136 | ->where('xref', '=', $xref) |
||
| 137 | ->delete(); |
||
| 138 | } |
||
| 139 | |||
| 140 | // Add (or update) the new data |
||
| 141 | if ($tag_type !== '' || $xref !== '') { |
||
| 142 | DB::table('default_resn')->insert([ |
||
| 143 | 'gedcom_id' => $tree->id(), |
||
| 144 | 'xref' => $xref === '' ? null : $xref, |
||
| 145 | 'tag_type' => $tag_type === '' ? null : $tag_type, |
||
| 146 | 'resn' => $resn, |
||
| 147 | ]); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | $tree->setPreference('HIDE_LIVE_PEOPLE', $params['HIDE_LIVE_PEOPLE']); |
||
| 152 | $tree->setPreference('KEEP_ALIVE_YEARS_BIRTH', $params['KEEP_ALIVE_YEARS_BIRTH']); |
||
| 153 | $tree->setPreference('KEEP_ALIVE_YEARS_DEATH', $params['KEEP_ALIVE_YEARS_DEATH']); |
||
| 154 | $tree->setPreference('MAX_ALIVE_AGE', $params['MAX_ALIVE_AGE']); |
||
| 155 | $tree->setPreference('REQUIRE_AUTHENTICATION', $params['REQUIRE_AUTHENTICATION']); |
||
| 156 | $tree->setPreference('SHOW_DEAD_PEOPLE', $params['SHOW_DEAD_PEOPLE']); |
||
| 157 | $tree->setPreference('SHOW_LIVING_NAMES', $params['SHOW_LIVING_NAMES']); |
||
| 158 | $tree->setPreference('SHOW_PRIVATE_RELATIONSHIPS', $params['SHOW_PRIVATE_RELATIONSHIPS']); |
||
| 159 | |||
| 160 | FlashMessages::addMessage(I18N::translate('The preferences for the family tree “%s” have been updated.', e($tree->title()), 'success')); |
||
| 161 | |||
| 162 | // Coming soon... |
||
| 163 | $all_trees = $request->getParsedBody()['all_trees'] ?? ''; |
||
| 164 | $new_trees = $request->getParsedBody()['new_trees'] ?? ''; |
||
| 165 | |||
| 166 | if ($all_trees === 'on') { |
||
| 167 | FlashMessages::addMessage(I18N::translate('The preferences for all family trees have been updated.', e($tree->title())), 'success'); |
||
| 168 | } |
||
| 169 | if ($new_trees === 'on') { |
||
| 170 | FlashMessages::addMessage(I18N::translate('The preferences for new family trees have been updated.', e($tree->title())), 'success'); |
||
| 171 | } |
||
| 172 | |||
| 173 | return redirect(route('manage-trees', ['tree' => $tree->name()])); |
||
| 174 | } |
||
| 274 |