Conditions | 34 |
Paths | > 20000 |
Total Lines | 213 |
Code Lines | 165 |
Lines | 53 |
Ratio | 24.88 % |
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 |
||
101 | private function printFamily(Family $family, $type, $label) { |
||
102 | global $controller; |
||
103 | |||
104 | if ($family->getTree()->getPreference('SHOW_PRIVATE_RELATIONSHIPS')) { |
||
105 | $access_level = Auth::PRIV_HIDE; |
||
106 | } else { |
||
107 | $access_level = Auth::accessLevel($family->getTree()); |
||
108 | } |
||
109 | |||
110 | ?> |
||
111 | <table> |
||
112 | <tr> |
||
113 | <td> |
||
114 | <i class="icon-cfamily"></i> |
||
115 | </td> |
||
116 | <td> |
||
117 | <span class="subheaders"> <?= $label ?></span> |
||
118 | <a href="<?= $family->getHtmlUrl() ?>"> - <?= I18N::translate('View this family') ?></a> |
||
119 | </td> |
||
120 | </tr> |
||
121 | </table> |
||
122 | |||
123 | <table class="table table-sm wt-facts-table"> |
||
124 | <caption></caption> |
||
125 | <tbody> |
||
126 | <?php |
||
127 | |||
128 | ///// HUSB ///// |
||
129 | $found = false; |
||
130 | View Code Duplication | foreach ($family->getFacts('HUSB', false, $access_level) as $fact) { |
|
131 | $found |= !$fact->isPendingDeletion(); |
||
132 | $person = $fact->getTarget(); |
||
133 | if ($person instanceof Individual) { |
||
134 | $row_class = 'wt-gender-' . $person->getSex(); |
||
135 | if ($fact->isPendingAddition()) { |
||
136 | $row_class .= ' new'; |
||
137 | } elseif ($fact->isPendingDeletion()) { |
||
138 | $row_class .= ' old'; |
||
139 | } |
||
140 | $icon = $controller->record === $person ? '<i class="icon-selected"></i>' : ''; |
||
141 | ?> |
||
142 | <tr class="<?= $row_class ?>"> |
||
143 | <th scope="row"> |
||
144 | <?= $icon ?> |
||
145 | <?= Functions::getCloseRelationshipName($controller->record, $person) ?> |
||
146 | </th> |
||
147 | <td class="border-0 p-0"> |
||
148 | <?= Theme::theme()->individualBoxLarge($person) ?> |
||
149 | </td> |
||
150 | </tr> |
||
151 | <?php |
||
152 | } |
||
153 | } |
||
154 | if (!$found && $family->canEdit()) { |
||
155 | ?> |
||
156 | <tr> |
||
157 | <th></th> |
||
158 | <td scope="row"> |
||
159 | <a href="edit_interface.php?action=add_spouse_to_family&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>&famtag=HUSB"> |
||
160 | <?= I18N::translate('Add a husband to this family') ?> |
||
161 | </a> |
||
162 | </td> |
||
163 | </tr> |
||
164 | <?php |
||
165 | } |
||
166 | |||
167 | ///// WIFE ///// |
||
168 | $found = false; |
||
169 | View Code Duplication | foreach ($family->getFacts('WIFE', false, $access_level) as $fact) { |
|
170 | $person = $fact->getTarget(); |
||
171 | if ($person instanceof Individual) { |
||
172 | $found |= !$fact->isPendingDeletion(); |
||
173 | $row_class = 'wt-gender-' . $person->getSex(); |
||
174 | if ($fact->isPendingAddition()) { |
||
175 | $row_class .= ' new'; |
||
176 | } elseif ($fact->isPendingDeletion()) { |
||
177 | $row_class .= ' old'; |
||
178 | } |
||
179 | $icon = $controller->record === $person ? '<i class="icon-selected"></i>' : ''; |
||
180 | ?> |
||
181 | <tr class="<?= $row_class ?>"> |
||
182 | <th scope="row"> |
||
183 | <?= $icon ?> |
||
184 | <?= Functions::getCloseRelationshipName($controller->record, $person) ?> |
||
185 | </th> |
||
186 | <td class="border-0 p-0"> |
||
187 | <?= Theme::theme()->individualBoxLarge($person) ?> |
||
188 | </td> |
||
189 | </tr> |
||
190 | <?php |
||
191 | } |
||
192 | } |
||
193 | if (!$found && $family->canEdit()) { |
||
194 | ?> |
||
195 | <tr> |
||
196 | <th scope="row"></th> |
||
197 | <td> |
||
198 | <a href="edit_interface.php?action=add_spouse_to_family&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>&famtag=WIFE"> |
||
199 | <?= I18N::translate('Add a wife to this family') ?> |
||
200 | </a> |
||
201 | </td> |
||
202 | </tr> |
||
203 | <?php |
||
204 | } |
||
205 | |||
206 | ///// MARR ///// |
||
207 | $found = false; |
||
208 | $prev = new Date(''); |
||
209 | foreach ($family->getFacts(WT_EVENTS_MARR . '|' . WT_EVENTS_DIV, true) as $fact) { |
||
210 | $found |= !$fact->isPendingDeletion(); |
||
211 | if ($fact->isPendingAddition()) { |
||
212 | $row_class = 'new'; |
||
213 | } elseif ($fact->isPendingDeletion()) { |
||
214 | $row_class = 'old'; |
||
215 | } else { |
||
216 | $row_class = ''; |
||
217 | } |
||
218 | ?> |
||
219 | <tr class="<?= $row_class ?>"> |
||
220 | <th scope="row"> |
||
221 | </th> |
||
222 | <td> |
||
223 | <?= GedcomTag::getLabelValue($fact->getTag(), $fact->getDate()->display() . ' — ' . $fact->getPlace()->getFullName()) ?> |
||
224 | </td> |
||
225 | </tr> |
||
226 | <?php |
||
227 | if (!$prev->isOK() && $fact->getDate()->isOK()) { |
||
228 | $prev = $fact->getDate(); |
||
229 | } |
||
230 | } |
||
231 | if (!$found && $family->canShow() && $family->canEdit()) { |
||
232 | // Add a new marriage |
||
233 | ?> |
||
234 | <tr> |
||
235 | <th scope="row"> |
||
236 | </th> |
||
237 | <td> |
||
238 | <a href="edit_interface.php?action=add&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>&fact=MARR"> |
||
239 | <?= I18N::translate('Add marriage details') ?> |
||
240 | </a> |
||
241 | </td> |
||
242 | </tr> |
||
243 | <?php |
||
244 | } |
||
245 | |||
246 | ///// CHIL ///// |
||
247 | $child_number = 0; |
||
248 | foreach ($family->getFacts('CHIL', false, $access_level) as $fact) { |
||
249 | $person = $fact->getTarget(); |
||
250 | if ($person instanceof Individual) { |
||
251 | $row_class = 'wt-gender-' . $person->getSex(); |
||
252 | if ($fact->isPendingAddition()) { |
||
253 | $child_number++; |
||
254 | $row_class .= ' new'; |
||
255 | } elseif ($fact->isPendingDeletion()) { |
||
256 | $row_class .= ' old'; |
||
257 | } else { |
||
258 | $child_number++; |
||
259 | } |
||
260 | $next = new Date(''); |
||
261 | foreach ($person->getFacts(WT_EVENTS_BIRT, true) as $bfact) { |
||
262 | if ($bfact->getDate()->isOK()) { |
||
263 | $next = $bfact->getDate(); |
||
264 | break; |
||
265 | } |
||
266 | } |
||
267 | $icon = $controller->record === $person ? '<i class="icon-selected"></i>' : ''; |
||
268 | ?> |
||
269 | <tr class="<?= $row_class ?>"> |
||
270 | <th scope="row"> |
||
271 | <?= $icon ?> |
||
272 | <?= self::ageDifference($prev, $next, $child_number) ?> |
||
273 | <?= Functions::getCloseRelationshipName($controller->record, $person) ?> |
||
274 | </th> |
||
275 | <td class="border-0 p-0"> |
||
276 | <?= Theme::theme()->individualBoxLarge($person) ?> |
||
277 | </td> |
||
278 | </tr> |
||
279 | <?php |
||
280 | $prev = $next; |
||
281 | } |
||
282 | } |
||
283 | // Re-order children / add a new child |
||
284 | if ($family->canEdit()) { |
||
285 | if ($type == 'FAMS') { |
||
286 | $add_child_text = I18N::translate('Add a son or daughter'); |
||
287 | } else { |
||
288 | $add_child_text = I18N::translate('Add a brother or sister'); |
||
289 | } |
||
290 | ?> |
||
291 | <tr> |
||
292 | <th scope="row"> |
||
293 | View Code Duplication | <?php if (count($family->getChildren()) > 1): ?> |
|
294 | <a href="edit_interface.php?action=reorder-children&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>"> |
||
295 | <i class="icon-media-shuffle"></i> <?= I18N::translate('Re-order children') ?> |
||
296 | </a> |
||
297 | <?php endif; ?> |
||
298 | </th> |
||
299 | <td> |
||
300 | <a href="edit_interface.php?action=add_child_to_family&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>&gender=U"> |
||
301 | <?= $add_child_text ?> |
||
302 | </a> |
||
303 | <span style='white-space:nowrap;'> |
||
304 | <a href="edit_interface.php?action=add_child_to_family&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>&gender=M" class="icon-sex_m_15x15"></a> |
||
305 | <a href="edit_interface.php?action=add_child_to_family&ged=<?= $family->getTree()->getNameHtml() ?>&xref=<?= $family->getXref() ?>&gender=F" class="icon-sex_f_15x15"></a> |
||
306 | </span> |
||
307 | </td> |
||
308 | </tr> |
||
309 | <?php |
||
310 | } |
||
311 | |||
312 | echo '</tbody>'; |
||
313 | echo '</table>'; |
||
314 | } |
||
460 |