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