| Conditions | 11 |
| Paths | 65 |
| Total Lines | 75 |
| Code Lines | 48 |
| 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 |
||
| 92 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 93 | { |
||
| 94 | $tree = $request->getAttribute('tree'); |
||
| 95 | assert($tree instanceof Tree); |
||
| 96 | |||
| 97 | $xref = $request->getAttribute('xref'); |
||
| 98 | assert(is_string($xref)); |
||
| 99 | |||
| 100 | $individual = Factory::individual()->make($xref, $tree); |
||
| 101 | $individual = Auth::checkIndividualAccess($individual); |
||
| 102 | |||
| 103 | // Redirect to correct xref/slug |
||
| 104 | if ($individual->xref() !== $xref || $request->getAttribute('slug') !== $individual->slug()) { |
||
| 105 | return redirect($individual->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY); |
||
| 106 | } |
||
| 107 | |||
| 108 | // What is (was) the age of the individual |
||
| 109 | $bdate = $individual->getBirthDate(); |
||
| 110 | $ddate = $individual->getDeathDate(); |
||
| 111 | |||
| 112 | if ($individual->isDead()) { |
||
| 113 | // If dead, show age at death |
||
| 114 | $age = (new Age($bdate, $ddate))->ageAtEvent(false); |
||
| 115 | } else { |
||
| 116 | // If living, show age today |
||
| 117 | $today = strtoupper(date('d M Y')); |
||
| 118 | $age = (new Age($bdate, new Date($today)))->ageAtEvent(true); |
||
| 119 | } |
||
| 120 | |||
| 121 | // What images are linked to this individual |
||
| 122 | $individual_media = new Collection(); |
||
| 123 | foreach ($individual->facts(['OBJE']) as $fact) { |
||
| 124 | $media_object = $fact->target(); |
||
| 125 | if ($media_object instanceof Media) { |
||
| 126 | $media_file = $media_object->firstImageFile(); |
||
| 127 | if ($media_file instanceof MediaFile) { |
||
| 128 | $individual_media->add($media_file); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | $name_records = new Collection(); |
||
| 134 | foreach ($individual->facts(['NAME']) as $n => $name_fact) { |
||
| 135 | $name_records->add(view('individual-name', ['fact' => $name_fact, 'n' => $n])); |
||
| 136 | } |
||
| 137 | |||
| 138 | $sex_records = new Collection(); |
||
| 139 | foreach ($individual->facts(['SEX']) as $n => $sex_fact) { |
||
| 140 | $sex_records->add(view('individual-sex', ['fact' => $sex_fact])); |
||
| 141 | } |
||
| 142 | |||
| 143 | // If this individual is linked to a user account, show the link |
||
| 144 | $user_link = ''; |
||
| 145 | if (Auth::isAdmin()) { |
||
| 146 | $users = $this->user_service->findByIndividual($individual); |
||
| 147 | foreach ($users as $user) { |
||
| 148 | $user_link = ' — <a href="' . e(route('admin-users', ['filter' => $user->email()])) . '">' . e($user->userName()) . '</a>'; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | return $this->viewResponse('individual-page', [ |
||
| 153 | 'age' => $age, |
||
| 154 | 'clipboard_facts' => $this->clipboard_service->pastableFacts($individual, new Collection()), |
||
| 155 | 'individual' => $individual, |
||
| 156 | 'individual_media' => $individual_media, |
||
| 157 | 'meta_description' => $this->metaDescription($individual), |
||
| 158 | 'meta_robots' => 'index,follow', |
||
| 159 | 'name_records' => $name_records, |
||
| 160 | 'sex_records' => $sex_records, |
||
| 161 | 'sidebars' => $this->getSidebars($individual), |
||
| 162 | 'tabs' => $this->getTabs($individual), |
||
| 163 | 'significant' => $this->significant($individual), |
||
| 164 | 'title' => $individual->fullName() . ' ' . $individual->lifespan(), |
||
| 165 | 'tree' => $tree, |
||
| 166 | 'user_link' => $user_link, |
||
| 167 | ]); |
||
| 276 |