| Conditions | 16 |
| Paths | 1944 |
| Total Lines | 117 |
| Code Lines | 75 |
| 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 |
||
| 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 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Names of our privacy levels |
||
| 178 | * |
||
| 179 | * @return array |
||
| 180 | */ |
||
| 181 | private function privacyConstants(): array |
||
| 182 | { |
||
| 183 | return [ |
||
| 184 | 'none' => I18N::translate('Show to visitors'), |
||
| 185 | 'privacy' => I18N::translate('Show to members'), |
||
| 186 | 'confidential' => I18N::translate('Show to managers'), |
||
| 187 | 'hidden' => I18N::translate('Hide from everyone'), |
||
| 188 | ]; |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * The current privacy restrictions for a tree. |
||
| 193 | * |
||
| 194 | * @param Tree $tree |
||
| 195 | * |
||
| 196 | * @return array |
||
| 197 | */ |
||
| 198 | private function privacyRestrictions(Tree $tree): array |
||
| 199 | { |
||
| 200 | return DB::table('default_resn') |
||
| 201 | ->where('gedcom_id', '=', $tree->id()) |
||
| 202 | ->get() |
||
| 203 | ->map(static function (stdClass $row) use ($tree): stdClass { |
||
| 204 | $row->record = null; |
||
| 205 | $row->label = ''; |
||
| 206 | |||
| 207 | if ($row->xref !== null) { |
||
| 208 | $row->record = GedcomRecord::getInstance($row->xref, $tree); |
||
| 209 | } |
||
| 210 | |||
| 211 | if ($row->tag_type) { |
||
| 212 | $row->tag_label = GedcomTag::getLabel($row->tag_type); |
||
| 213 | } else { |
||
| 214 | $row->tag_label = ''; |
||
| 215 | } |
||
| 216 | |||
| 217 | return $row; |
||
| 218 | }) |
||
| 219 | ->sort(static function (stdClass $x, stdClass $y): int { |
||
| 220 | return I18N::strcasecmp($x->tag_label, $y->tag_label); |
||
| 221 | }) |
||
| 222 | ->all(); |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Generate a list of potential problems with the server. |
||
| 227 | * |
||
| 228 | * @param Tree $tree |
||
| 229 | * |
||
| 230 | * @return string[] |
||
| 231 | */ |
||
| 232 | private function tagsForPrivacy(Tree $tree): array |
||
| 233 | { |
||
| 234 | $tags = array_unique(array_merge( |
||
| 235 | explode(',', $tree->getPreference('INDI_FACTS_ADD')), |
||
| 236 | explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')), |
||
| 237 | explode(',', $tree->getPreference('FAM_FACTS_ADD')), |
||
| 238 | explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')), |
||
| 239 | explode(',', $tree->getPreference('NOTE_FACTS_ADD')), |
||
| 240 | explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')), |
||
| 241 | explode(',', $tree->getPreference('SOUR_FACTS_ADD')), |
||
| 242 | explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')), |
||
| 243 | explode(',', $tree->getPreference('REPO_FACTS_ADD')), |
||
| 244 | explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')), |
||
| 245 | [ |
||
| 246 | 'SOUR', |
||
| 247 | 'REPO', |
||
| 248 | 'OBJE', |
||
| 249 | '_PRIM', |
||
| 250 | 'NOTE', |
||
| 251 | 'SUBM', |
||
| 252 | 'SUBN', |
||
| 253 | '_UID', |
||
| 254 | 'CHAN', |
||
| 255 | ] |
||
| 256 | )); |
||
| 257 | |||
| 258 | $all_tags = []; |
||
| 259 | |||
| 260 | foreach ($tags as $tag) { |
||
| 261 | if ($tag) { |
||
| 262 | $all_tags[$tag] = GedcomTag::getLabel($tag); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp'); |
||
| 267 | |||
| 268 | return array_merge( |
||
| 269 | ['' => I18N::translate('All facts and events')], |
||
| 270 | $all_tags |
||
| 271 | ); |
||
| 272 | } |
||
| 273 | } |
||
| 274 |