| Conditions | 3 |
| Paths | 3 |
| Total Lines | 129 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 78 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 79 | { |
||
| 80 | $this->layout = 'layouts/administration'; |
||
| 81 | |||
| 82 | $tree = $request->getAttribute('tree'); |
||
| 83 | assert($tree instanceof Tree); |
||
| 84 | |||
| 85 | $data_folder = Factory::filesystem()->dataName(); |
||
| 86 | |||
| 87 | $french_calendar_start = new Date('22 SEP 1792'); |
||
| 88 | $french_calendar_end = new Date('31 DEC 1805'); |
||
| 89 | $gregorian_calendar_start = new Date('15 OCT 1582'); |
||
| 90 | |||
| 91 | $surname_list_styles = [ |
||
| 92 | /* I18N: Layout option for lists of names */ |
||
| 93 | 'style1' => I18N::translate('list'), |
||
| 94 | /* I18N: Layout option for lists of names */ |
||
| 95 | 'style2' => I18N::translate('table'), |
||
| 96 | /* I18N: Layout option for lists of names */ |
||
| 97 | 'style3' => I18N::translate('tag cloud'), |
||
| 98 | ]; |
||
| 99 | |||
| 100 | $page_layouts = [ |
||
| 101 | /* I18N: page orientation */ |
||
| 102 | 0 => I18N::translate('Portrait'), |
||
| 103 | /* I18N: page orientation */ |
||
| 104 | 1 => I18N::translate('Landscape'), |
||
| 105 | ]; |
||
| 106 | |||
| 107 | $formats = [ |
||
| 108 | /* I18N: None of the other options */ |
||
| 109 | '' => I18N::translate('none'), |
||
| 110 | /* I18N: https://en.wikipedia.org/wiki/Markdown */ |
||
| 111 | 'markdown' => I18N::translate('markdown'), |
||
| 112 | ]; |
||
| 113 | |||
| 114 | $source_types = [ |
||
| 115 | 0 => I18N::translate('none'), |
||
| 116 | 1 => I18N::translate('facts'), |
||
| 117 | 2 => I18N::translate('records'), |
||
| 118 | ]; |
||
| 119 | |||
| 120 | $theme_options = $this->module_service |
||
| 121 | ->findByInterface(ModuleThemeInterface::class) |
||
| 122 | ->map($this->module_service->titleMapper()) |
||
| 123 | ->prepend(I18N::translate('<default theme>'), ''); |
||
| 124 | |||
| 125 | $privacy_options = [ |
||
| 126 | Auth::PRIV_USER => I18N::translate('Show to members'), |
||
| 127 | Auth::PRIV_NONE => I18N::translate('Show to managers'), |
||
| 128 | Auth::PRIV_HIDE => I18N::translate('Hide from everyone'), |
||
| 129 | ]; |
||
| 130 | |||
| 131 | $tags = array_unique(array_merge( |
||
| 132 | explode(',', $tree->getPreference('INDI_FACTS_ADD')), |
||
| 133 | explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')), |
||
| 134 | explode(',', $tree->getPreference('FAM_FACTS_ADD')), |
||
| 135 | explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')), |
||
| 136 | explode(',', $tree->getPreference('NOTE_FACTS_ADD')), |
||
| 137 | explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')), |
||
| 138 | explode(',', $tree->getPreference('SOUR_FACTS_ADD')), |
||
| 139 | explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')), |
||
| 140 | explode(',', $tree->getPreference('REPO_FACTS_ADD')), |
||
| 141 | explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')), |
||
| 142 | ['SOUR', 'REPO', 'OBJE', '_PRIM', 'NOTE', 'SUBM', 'SUBN', '_UID', 'CHAN'] |
||
| 143 | )); |
||
| 144 | |||
| 145 | $all_tags = []; |
||
| 146 | foreach ($tags as $tag) { |
||
| 147 | if ($tag) { |
||
| 148 | $all_tags[$tag] = GedcomTag::getLabel($tag); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp'); |
||
| 153 | |||
| 154 | // For historical reasons, we have two fields in one |
||
| 155 | $calendar_formats = explode('_and_', $tree->getPreference('CALENDAR_FORMAT') . '_and_'); |
||
| 156 | |||
| 157 | // Split into separate fields |
||
| 158 | $relatives_events = explode(',', $tree->getPreference('SHOW_RELATIVES_EVENTS')); |
||
| 159 | |||
| 160 | $pedigree_individual = Factory::individual()->make($tree->getPreference('PEDIGREE_ROOT_ID'), $tree); |
||
| 161 | |||
| 162 | $members = $this->user_service->all()->filter(static function (UserInterface $user) use ($tree): bool { |
||
| 163 | return Auth::isMember($tree, $user); |
||
| 164 | }); |
||
| 165 | |||
| 166 | $all_fam_facts = GedcomTag::getPicklistFacts('FAM'); |
||
| 167 | $all_indi_facts = GedcomTag::getPicklistFacts('INDI'); |
||
| 168 | $all_name_facts = GedcomTag::getPicklistFacts('NAME'); |
||
| 169 | $all_plac_facts = GedcomTag::getPicklistFacts('PLAC'); |
||
| 170 | $all_repo_facts = GedcomTag::getPicklistFacts('REPO'); |
||
| 171 | $all_sour_facts = GedcomTag::getPicklistFacts('SOUR'); |
||
| 172 | |||
| 173 | $all_surname_traditions = SurnameTradition::allDescriptions(); |
||
| 174 | |||
| 175 | $tree_count = $this->tree_service->all()->count(); |
||
| 176 | |||
| 177 | $title = I18N::translate('Preferences') . ' — ' . e($tree->title()); |
||
| 178 | |||
| 179 | $base_url = app(ServerRequestInterface::class)->getAttribute('base_url'); |
||
| 180 | |||
| 181 | return $this->viewResponse('admin/trees-preferences', [ |
||
| 182 | 'all_fam_facts' => $all_fam_facts, |
||
| 183 | 'all_indi_facts' => $all_indi_facts, |
||
| 184 | 'all_name_facts' => $all_name_facts, |
||
| 185 | 'all_plac_facts' => $all_plac_facts, |
||
| 186 | 'all_repo_facts' => $all_repo_facts, |
||
| 187 | 'all_sour_facts' => $all_sour_facts, |
||
| 188 | 'all_surname_traditions' => $all_surname_traditions, |
||
| 189 | 'base_url' => $base_url, |
||
| 190 | 'calendar_formats' => $calendar_formats, |
||
| 191 | 'data_folder' => $data_folder, |
||
| 192 | 'formats' => $formats, |
||
| 193 | 'french_calendar_end' => $french_calendar_end, |
||
| 194 | 'french_calendar_start' => $french_calendar_start, |
||
| 195 | 'gregorian_calendar_start' => $gregorian_calendar_start, |
||
| 196 | 'members' => $members, |
||
| 197 | 'page_layouts' => $page_layouts, |
||
| 198 | 'pedigree_individual' => $pedigree_individual, |
||
| 199 | 'privacy_options' => $privacy_options, |
||
| 200 | 'relatives_events' => $relatives_events, |
||
| 201 | 'source_types' => $source_types, |
||
| 202 | 'surname_list_styles' => $surname_list_styles, |
||
| 203 | 'theme_options' => $theme_options, |
||
| 204 | 'title' => $title, |
||
| 205 | 'tree' => $tree, |
||
| 206 | 'tree_count' => $tree_count, |
||
| 207 | ]); |
||
| 210 |