| Conditions | 3 |
| Paths | 3 |
| Total Lines | 60 |
| Code Lines | 43 |
| 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 |
||
| 154 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 155 | { |
||
| 156 | $tree = $request->getAttribute('tree'); |
||
| 157 | $user = $request->getAttribute('user'); |
||
| 158 | $xref = $request->getAttribute('xref'); |
||
| 159 | $book_size = (int) $request->getAttribute('book_size'); |
||
| 160 | $generations = (int) $request->getAttribute('generations'); |
||
| 161 | $spouses = (bool) $request->getAttribute('spouses'); |
||
| 162 | $ajax = $request->getQueryParams()['ajax'] ?? ''; |
||
| 163 | $individual = Individual::getInstance($xref, $tree); |
||
| 164 | |||
| 165 | // Convert POST requests into GET requests for pretty URLs. |
||
| 166 | if ($request->getMethod() === RequestMethodInterface::METHOD_POST) { |
||
| 167 | return redirect(route(self::ROUTE_NAME, [ |
||
| 168 | 'tree' => $request->getAttribute('tree')->name(), |
||
| 169 | 'xref' => $request->getParsedBody()['xref'], |
||
| 170 | 'book_size' => $request->getParsedBody()['book_size'], |
||
| 171 | 'generations' => $request->getParsedBody()['generations'], |
||
| 172 | 'spouses' => $request->getParsedBody()['spouses'] ?? false, |
||
| 173 | ])); |
||
| 174 | } |
||
| 175 | |||
| 176 | Auth::checkIndividualAccess($individual); |
||
| 177 | Auth::checkComponentAccess($this, 'chart', $tree, $user); |
||
| 178 | |||
| 179 | $generations = min($generations, self::MAXIMUM_GENERATIONS); |
||
| 180 | $generations = max($generations, self::MINIMUM_GENERATIONS); |
||
| 181 | |||
| 182 | // Generations of ancestors/descendants in each mini-tree. |
||
| 183 | $book_size = min($book_size, 5); |
||
| 184 | $book_size = max($book_size, 2); |
||
| 185 | |||
| 186 | if ($ajax === '1') { |
||
| 187 | $this->layout = 'layouts/ajax'; |
||
| 188 | |||
| 189 | return $this->viewResponse('modules/family-book-chart/chart', [ |
||
| 190 | 'individual' => $individual, |
||
| 191 | 'generations' => $generations, |
||
| 192 | 'book_size' => $book_size, |
||
| 193 | 'spouses' => $spouses, |
||
| 194 | ]); |
||
| 195 | } |
||
| 196 | |||
| 197 | $ajax_url = $this->chartUrl($individual, [ |
||
| 198 | 'ajax' => true, |
||
| 199 | 'book_size' => $book_size, |
||
| 200 | 'generations' => $generations, |
||
| 201 | 'spouses' => $spouses, |
||
| 202 | ]); |
||
| 203 | |||
| 204 | return $this->viewResponse('modules/family-book-chart/page', [ |
||
| 205 | 'ajax_url' => $ajax_url, |
||
| 206 | 'book_size' => $book_size, |
||
| 207 | 'generations' => $generations, |
||
| 208 | 'individual' => $individual, |
||
| 209 | 'maximum_generations' => self::MAXIMUM_GENERATIONS, |
||
| 210 | 'minimum_generations' => self::MINIMUM_GENERATIONS, |
||
| 211 | 'module' => $this->name(), |
||
| 212 | 'spouses' => $spouses, |
||
| 213 | 'title' => $this->chartTitle($individual), |
||
| 214 | ]); |
||
| 217 |