| Conditions | 52 | 
| Paths | > 20000 | 
| Total Lines | 292 | 
| Code Lines | 227 | 
| 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 | ||
| 174 | protected function createResponse(Tree $tree, UserInterface $user, array $params, bool $families): ResponseInterface | ||
| 175 |     { | ||
| 176 | ob_start(); | ||
| 177 | |||
| 178 | // We show three different lists: initials, surnames and individuals | ||
| 179 | |||
| 180 | // All surnames beginning with this letter where "@"=unknown and ","=none | ||
| 181 | $alpha = $params['alpha']; | ||
| 182 | |||
| 183 | // All individuals with this surname | ||
| 184 | $surname = $params['surname']; | ||
| 185 | |||
| 186 | // All individuals | ||
| 187 | $show_all = $params['show_all']; | ||
| 188 | |||
| 189 | // Long lists can be broken down by given name | ||
| 190 | $show_all_firstnames = $params['show_all_firstnames']; | ||
| 191 |         if ($show_all_firstnames === 'yes') { | ||
| 192 | $falpha = ''; | ||
| 193 |         } else { | ||
| 194 | // All first names beginning with this letter | ||
| 195 | $falpha = $params['falpha']; | ||
| 196 | } | ||
| 197 | |||
| 198 | $show_marnm = $params['show_marnm']; | ||
| 199 |         switch ($show_marnm) { | ||
| 200 | case 'no': | ||
| 201 | case 'yes': | ||
| 202 | $user->setPreference($families ? 'family-list-marnm' : 'individual-list-marnm', $show_marnm); | ||
| 203 | break; | ||
| 204 | default: | ||
| 205 | $show_marnm = $user->getPreference($families ? 'family-list-marnm' : 'individual-list-marnm'); | ||
| 206 | } | ||
| 207 | |||
| 208 | // Make sure selections are consistent. | ||
| 209 | // i.e. can’t specify show_all and surname at the same time. | ||
| 210 |         if ($show_all === 'yes') { | ||
| 211 | $alpha = ''; | ||
| 212 | $surname = ''; | ||
| 213 | |||
| 214 |             if ($show_all_firstnames === 'yes') { | ||
| 215 |                 $legend  = I18N::translate('All'); | ||
| 216 | $params = [ | ||
| 217 | 'tree' => $tree->name(), | ||
| 218 | 'show_all' => 'yes', | ||
| 219 | ]; | ||
| 220 | $show = 'indi'; | ||
| 221 |             } elseif ($falpha !== '') { | ||
| 222 |                 $legend  = I18N::translate('All') . ', ' . e($falpha) . '…'; | ||
| 223 | $params = [ | ||
| 224 | 'tree' => $tree->name(), | ||
| 225 | 'show_all' => 'yes', | ||
| 226 | ]; | ||
| 227 | $show = 'indi'; | ||
| 228 |             } else { | ||
| 229 |                 $legend  = I18N::translate('All'); | ||
| 230 | $show = $params['show']; | ||
| 231 | $params = [ | ||
| 232 | 'tree' => $tree->name(), | ||
| 233 | 'show_all' => 'yes', | ||
| 234 | ]; | ||
| 235 | } | ||
| 236 |         } elseif ($surname !== '') { | ||
| 237 | $alpha = I18N::language()->initialLetter($surname); // so we can highlight the initial letter | ||
| 238 | $show_all = 'no'; | ||
| 239 |             if ($surname === Individual::NOMEN_NESCIO) { | ||
| 240 |                 $legend = I18N::translateContext('Unknown surname', '…'); | ||
| 241 |             } else { | ||
| 242 | // The surname parameter is a root/canonical form. | ||
| 243 | // Display it as the actual surname | ||
| 244 |                 $legend = implode('/', array_keys($this->surnames($tree, $surname, $alpha, $show_marnm === 'yes', $families, I18N::locale()))); | ||
| 245 | } | ||
| 246 | $params = [ | ||
| 247 | 'tree' => $tree->name(), | ||
| 248 | 'surname' => $surname, | ||
| 249 | 'falpha' => $falpha, | ||
| 250 | ]; | ||
| 251 |             switch ($falpha) { | ||
| 252 | case '': | ||
| 253 | break; | ||
| 254 | case '@': | ||
| 255 |                     $legend .= ', ' . I18N::translateContext('Unknown given name', '…'); | ||
| 256 | break; | ||
| 257 | default: | ||
| 258 | $legend .= ', ' . e($falpha) . '…'; | ||
| 259 | break; | ||
| 260 | } | ||
| 261 | $show = 'indi'; // SURN list makes no sense here | ||
| 262 |         } elseif ($alpha === '@') { | ||
| 263 | $show_all = 'no'; | ||
| 264 |             $legend   = I18N::translateContext('Unknown surname', '…'); | ||
| 265 | $params = [ | ||
| 266 | 'alpha' => $alpha, | ||
| 267 | 'tree' => $tree->name(), | ||
| 268 | ]; | ||
| 269 | $show = 'indi'; // SURN list makes no sense here | ||
| 270 |         } elseif ($alpha === ',') { | ||
| 271 | $show_all = 'no'; | ||
| 272 |             $legend   = I18N::translate('No surname'); | ||
| 273 | $params = [ | ||
| 274 | 'alpha' => $alpha, | ||
| 275 | 'tree' => $tree->name(), | ||
| 276 | ]; | ||
| 277 | $show = 'indi'; // SURN list makes no sense here | ||
| 278 |         } elseif ($alpha !== '') { | ||
| 279 | $show_all = 'no'; | ||
| 280 | $legend = e($alpha) . '…'; | ||
| 281 | $show = $params['show']; | ||
| 282 | $params = [ | ||
| 283 | 'alpha' => $alpha, | ||
| 284 | 'tree' => $tree->name(), | ||
| 285 | ]; | ||
| 286 |         } else { | ||
| 287 | $show_all = 'no'; | ||
| 288 | $legend = '…'; | ||
| 289 | $params = [ | ||
| 290 | 'tree' => $tree->name(), | ||
| 291 | ]; | ||
| 292 | $show = 'none'; // Don't show lists until something is chosen | ||
| 293 | } | ||
| 294 | $legend = '<bdi>' . $legend . '</bdi>'; | ||
| 295 | |||
| 296 |         if ($families) { | ||
| 297 |             $title = I18N::translate('Families') . ' — ' . $legend; | ||
| 298 |         } else { | ||
| 299 |             $title = I18N::translate('Individuals') . ' — ' . $legend; | ||
| 300 | } ?> | ||
| 301 | <div class="d-flex flex-column wt-page-options wt-page-options-individual-list d-print-none"> | ||
| 302 | <ul class="d-flex flex-wrap list-unstyled justify-content-center wt-initials-list wt-initials-list-surname"> | ||
| 303 | |||
| 304 | <?php foreach ($this->surnameAlpha($tree, $show_marnm === 'yes', $families, I18N::locale()) as $letter => $count) : ?> | ||
| 305 | <li class="wt-initials-list-item d-flex"> | ||
| 306 | <?php if ($count > 0) : ?> | ||
| 307 | <a href="<?= e($this->listUrl($tree, ['alpha' => $letter, 'tree' => $tree->name()])) ?>" class="wt-initial px-1<?= $letter === $alpha ? ' active' : '' ?> '" title="<?= I18N::number($count) ?>"><?= $this->surnameInitial((string) $letter) ?></a> | ||
| 308 | <?php else : ?> | ||
| 309 | <span class="wt-initial px-1 text-muted"><?= $this->surnameInitial((string) $letter) ?></span> | ||
| 310 | |||
| 311 | <?php endif ?> | ||
| 312 | </li> | ||
| 313 | <?php endforeach ?> | ||
| 314 | |||
| 315 |                 <?php if (Session::has('initiated')) : ?> | ||
| 316 | <!-- Search spiders don't get the "show all" option as the other links give them everything. --> | ||
| 317 | <li class="wt-initials-list-item d-flex"> | ||
| 318 |                         <a class="wt-initial px-1<?= $show_all === 'yes' ? ' active' : '' ?>" href="<?= e($this->listUrl($tree, ['show_all' => 'yes'] + $params)) ?>"><?= I18N::translate('All') ?></a> | ||
| 319 | </li> | ||
| 320 | <?php endif ?> | ||
| 321 | </ul> | ||
| 322 | |||
| 323 | <!-- Search spiders don't get an option to show/hide the surname sublists, nor does it make sense on the all/unknown/surname views --> | ||
| 324 |             <?php if ($show !== 'none' && Session::has('initiated')) : ?> | ||
| 325 | <?php if ($show_marnm === 'yes') : ?> | ||
| 326 | <p> | ||
| 327 | <a href="<?= e($this->listUrl($tree, ['show' => $show, 'show_marnm' => 'no'] + $params)) ?>"> | ||
| 328 |                             <?= I18N::translate('Exclude individuals with “%s” as a married name', $legend) ?> | ||
| 329 | </a> | ||
| 330 | </p> | ||
| 331 | <?php else : ?> | ||
| 332 | <p> | ||
| 333 | <a href="<?= e($this->listUrl($tree, ['show' => $show, 'show_marnm' => 'yes'] + $params)) ?>"> | ||
| 334 |                             <?= I18N::translate('Include individuals with “%s” as a married name', $legend) ?> | ||
| 335 | </a> | ||
| 336 | </p> | ||
| 337 | <?php endif ?> | ||
| 338 | |||
| 339 | <?php if ($alpha !== '@' && $alpha !== ',' && $surname === '') : ?> | ||
| 340 | <?php if ($show === 'surn') : ?> | ||
| 341 | <p> | ||
| 342 | <a href="<?= e($this->listUrl($tree, ['show' => 'indi', 'show_marnm' => 'no'] + $params)) ?>"> | ||
| 343 |                                 <?= I18N::translate('Show the list of individuals') ?> | ||
| 344 | </a> | ||
| 345 | </p> | ||
| 346 | <?php else : ?> | ||
| 347 | <p> | ||
| 348 | <a href="<?= e($this->listUrl($tree, ['show' => 'surn', 'show_marnm' => 'no'] + $params)) ?>"> | ||
| 349 |                                 <?= I18N::translate('Show the list of surnames') ?> | ||
| 350 | </a> | ||
| 351 | </p> | ||
| 352 | <?php endif ?> | ||
| 353 | <?php endif ?> | ||
| 354 | <?php endif ?> | ||
| 355 | </div> | ||
| 356 | |||
| 357 | <div class="wt-page-content"> | ||
| 358 | <?php | ||
| 359 | |||
| 360 |             if ($show === 'indi' || $show === 'surn') { | ||
| 361 | $surns = $this->surnames($tree, $surname, $alpha, $show_marnm === 'yes', $families, I18N::locale()); | ||
| 362 |                 if ($show === 'surn') { | ||
| 363 | // Show the surname list | ||
| 364 |                     switch ($tree->getPreference('SURNAME_LIST_STYLE')) { | ||
| 365 | case 'style1': | ||
| 366 |                             echo view('lists/surnames-column-list', [ | ||
| 367 | 'module' => $this, | ||
| 368 | 'surnames' => $surns, | ||
| 369 | 'totals' => true, | ||
| 370 | 'tree' => $tree, | ||
| 371 | ]); | ||
| 372 | break; | ||
| 373 | case 'style3': | ||
| 374 |                             echo view('lists/surnames-tag-cloud', [ | ||
| 375 | 'module' => $this, | ||
| 376 | 'surnames' => $surns, | ||
| 377 | 'totals' => true, | ||
| 378 | 'tree' => $tree, | ||
| 379 | ]); | ||
| 380 | break; | ||
| 381 | case 'style2': | ||
| 382 | default: | ||
| 383 |                             echo view('lists/surnames-table', [ | ||
| 384 | 'families' => $families, | ||
| 385 | 'module' => $this, | ||
| 386 | 'order' => [[0, 'asc']], | ||
| 387 | 'surnames' => $surns, | ||
| 388 | 'tree' => $tree, | ||
| 389 | ]); | ||
| 390 | break; | ||
| 391 | } | ||
| 392 |                 } else { | ||
| 393 | // Show the list | ||
| 394 | $count = 0; | ||
| 395 |                     foreach ($surns as $surnames) { | ||
| 396 |                         foreach ($surnames as $total) { | ||
| 397 | $count += $total; | ||
| 398 | } | ||
| 399 | } | ||
| 400 | // Don't sublist short lists. | ||
| 401 |                     if ($count < $tree->getPreference('SUBLIST_TRIGGER_I')) { | ||
| 402 | $falpha = ''; | ||
| 403 |                     } else { | ||
| 404 | $givn_initials = $this->givenAlpha($tree, $surname, $alpha, $show_marnm === 'yes', $families, I18N::locale()); | ||
| 405 | // Break long lists by initial letter of given name | ||
| 406 |                         if ($surname !== '' || $show_all === 'yes') { | ||
| 407 |                             if ($show_all === 'no') { | ||
| 408 |                                 echo '<h2 class="wt-page-title">', I18N::translate('Individuals with surname %s', $legend), '</h2>'; | ||
| 409 | } | ||
| 410 | // Don't show the list until we have some filter criteria | ||
| 411 | $show = $falpha !== '' || $show_all_firstnames === 'yes' ? 'indi' : 'none'; | ||
| 412 | $list = []; | ||
| 413 | echo '<ul class="d-flex flex-wrap list-unstyled justify-content-center wt-initials-list wt-initials-list-given-names">'; | ||
| 414 |                             foreach ($givn_initials as $givn_initial => $given_count) { | ||
| 415 | echo '<li class="wt-initials-list-item d-flex">'; | ||
| 416 |                                 if ($given_count > 0) { | ||
| 417 |                                     if ($show === 'indi' && $givn_initial === $falpha && $show_all_firstnames === 'no') { | ||
| 418 | echo '<a class="wt-initial px-1 active" href="' . e($this->listUrl($tree, ['falpha' => $givn_initial] + $params)) . '" title="' . I18N::number($given_count) . '">' . $this->givenNameInitial((string) $givn_initial) . '</a>'; | ||
| 419 |                                     } else { | ||
| 420 | echo '<a class="wt-initial px-1" href="' . e($this->listUrl($tree, ['falpha' => $givn_initial] + $params)) . '" title="' . I18N::number($given_count) . '">' . $this->givenNameInitial((string) $givn_initial) . '</a>'; | ||
| 421 | } | ||
| 422 |                                 } else { | ||
| 423 | echo '<span class="wt-initial px-1 text-muted">' . $this->givenNameInitial((string) $givn_initial) . '</span>'; | ||
| 424 | } | ||
| 425 | echo '</li>'; | ||
| 426 | } | ||
| 427 | // Search spiders don't get the "show all" option as the other links give them everything. | ||
| 428 |                             if (Session::has('initiated')) { | ||
| 429 | echo '<li class="wt-initials-list-item d-flex">'; | ||
| 430 |                                 if ($show_all_firstnames === 'yes') { | ||
| 431 |                                     echo '<span class="wt-initial px-1 active">' . I18N::translate('All') . '</span>'; | ||
| 432 |                                 } else { | ||
| 433 |                                     echo '<a class="wt-initial px-1" href="' . e($this->listUrl($tree, ['show_all_firstnames' => 'yes'] + $params)) . '" title="' . I18N::number($count) . '">' . I18N::translate('All') . '</a>'; | ||
| 434 | } | ||
| 435 | echo '</li>'; | ||
| 436 | } | ||
| 437 | echo '</ul>'; | ||
| 438 |                             echo '<p class="text-center alpha_index">', implode(' | ', $list), '</p>'; | ||
| 439 | } | ||
| 440 | } | ||
| 441 |                     if ($show === 'indi') { | ||
| 442 |                         if ($families) { | ||
| 443 |                             echo view('lists/families-table', [ | ||
| 444 | 'families' => $this->families($tree, $surname, $alpha, $falpha, $show_marnm === 'yes', I18N::locale()), | ||
| 445 | 'tree' => $tree, | ||
| 446 | ]); | ||
| 447 |                         } else { | ||
| 448 |                             echo view('lists/individuals-table', [ | ||
| 449 | 'individuals' => $this->individuals($tree, $surname, $alpha, $falpha, $show_marnm === 'yes', false, I18N::locale()), | ||
| 450 | 'sosa' => false, | ||
| 451 | 'tree' => $tree, | ||
| 452 | ]); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | } | ||
| 456 | } ?> | ||
| 457 | </div> | ||
| 458 | <?php | ||
| 459 | |||
| 460 | $html = ob_get_clean(); | ||
| 461 | |||
| 462 |         return $this->viewResponse('modules/individual-list/page', [ | ||
| 463 | 'content' => $html, | ||
| 464 | 'title' => $title, | ||
| 465 | 'tree' => $tree, | ||
| 466 | ]); | ||
| 1024 |