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