Conditions | 32 |
Paths | 592 |
Total Lines | 82 |
Code Lines | 52 |
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 |
||
71 | $tree = $request->getAttribute('tree'); |
||
72 | assert($tree instanceof Tree); |
||
73 | |||
74 | $title = e($tree->name()) . ' — ' . I18N::translate('Privacy'); |
||
75 | $all_tags = $this->tagsForPrivacy($tree); |
||
76 | $privacy_constants = $this->privacyConstants(); |
||
77 | $privacy_restrictions = $this->privacyRestrictions($tree); |
||
78 | |||
79 | return $this->viewResponse('admin/trees-privacy', [ |
||
80 | 'all_tags' => $all_tags, |
||
81 | 'count_trees' => $this->tree_service->all()->count(), |
||
82 | 'privacy_constants' => $privacy_constants, |
||
83 | 'privacy_restrictions' => $privacy_restrictions, |
||
84 | 'title' => $title, |
||
85 | 'tree' => $tree, |
||
86 | ]); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param ServerRequestInterface $request |
||
91 | * |
||
92 | * @return ResponseInterface |
||
93 | */ |
||
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']); |
||
274 |