| Conditions | 9 |
| Paths | 3 |
| Total Lines | 52 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 69 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 70 | { |
||
| 71 | if ($this->module === null) { |
||
| 72 | throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
||
| 73 | } |
||
| 74 | |||
| 75 | $tree = $request->getAttribute('tree'); |
||
| 76 | assert($tree instanceof Tree); |
||
| 77 | |||
| 78 | $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
||
| 79 | |||
| 80 | /** @var SosaStatisticsService $sosa_stats_service */ |
||
| 81 | $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
||
| 82 | |||
| 83 | $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0); |
||
| 84 | |||
| 85 | $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen); |
||
| 86 | $nb_missing_diff = $list_missing->sum(function (stdClass $value): int { |
||
| 87 | return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0); |
||
| 88 | }); |
||
| 89 | |||
| 90 | $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor { |
||
| 91 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
||
| 92 | if ($indi !== null && $indi->canShowName()) { |
||
| 93 | return new MissingAncestor( |
||
| 94 | $indi, |
||
| 95 | (int) $value->majs_sosa, |
||
| 96 | $value->majs_fat_id === null, |
||
| 97 | $value->majs_mot_id === null |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | return null; |
||
| 101 | })->filter(); |
||
| 102 | |||
| 103 | $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int { |
||
| 104 | return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0); |
||
| 105 | }); |
||
| 106 | |||
| 107 | return $this->viewResponse($this->module->name() . '::list-missing-page', [ |
||
| 108 | 'module_name' => $this->module->name(), |
||
| 109 | 'title' => I18N::translate('Missing Ancestors'), |
||
| 110 | 'tree' => $tree, |
||
| 111 | 'root_indi' => $sosa_stats_service->rootIndividual(), |
||
| 112 | 'max_gen' => $sosa_stats_service->maxGeneration(), |
||
| 113 | 'current_gen' => $current_gen, |
||
| 114 | 'list_missing' => $list_missing, |
||
| 115 | 'nb_missing_diff' => $nb_missing_diff, |
||
| 116 | 'nb_missing_shown' => $nb_missing_shown, |
||
| 117 | 'gen_completeness' => |
||
| 118 | $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1), |
||
| 119 | 'gen_potential' => |
||
| 120 | $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2) |
||
| 121 | ]); |
||
| 124 |