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