Conditions | 8 |
Paths | 8 |
Total Lines | 81 |
Code Lines | 56 |
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 |
||
170 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
171 | { |
||
172 | $ajax = $request->getQueryParams()['ajax'] ?? ''; |
||
173 | $generations = (int) $request->getAttribute('generations'); |
||
174 | $style = $request->getAttribute('style'); |
||
175 | $tree = $request->getAttribute('tree'); |
||
176 | $user = $request->getAttribute('user'); |
||
177 | $xref = $request->getAttribute('xref'); |
||
178 | $individual = Individual::getInstance($xref, $tree); |
||
179 | |||
180 | // Convert POST requests into GET requests for pretty URLs. |
||
181 | if ($request->getMethod() === RequestMethodInterface::METHOD_POST) { |
||
182 | return redirect(route(self::ROUTE_NAME, [ |
||
183 | 'tree' => $request->getAttribute('tree')->name(), |
||
184 | 'xref' => $request->getParsedBody()['xref'], |
||
185 | 'style' => $request->getParsedBody()['style'], |
||
186 | 'generations' => $request->getParsedBody()['generations'], |
||
187 | ])); |
||
188 | } |
||
189 | |||
190 | Auth::checkIndividualAccess($individual); |
||
191 | Auth::checkComponentAccess($this, 'chart', $tree, $user); |
||
192 | |||
193 | $generations = min($generations, self::MAXIMUM_GENERATIONS); |
||
194 | $generations = max($generations, self::MINIMUM_GENERATIONS); |
||
195 | |||
196 | if ($ajax === '1') { |
||
197 | $this->layout = 'layouts/ajax'; |
||
198 | |||
199 | $ancestors = $this->chart_service->sosaStradonitzAncestors($individual, $generations); |
||
200 | |||
201 | switch ($style) { |
||
202 | default: |
||
203 | case self::CHART_STYLE_TREE: |
||
204 | return $this->viewResponse('modules/ancestors-chart/tree', [ |
||
205 | 'individual' => $individual, |
||
206 | 'parents' => $individual->primaryChildFamily(), |
||
207 | 'generations' => $generations, |
||
208 | 'sosa' => 1, |
||
209 | ]); |
||
210 | |||
211 | case self::CHART_STYLE_INDIVIDUALS: |
||
212 | return $this->viewResponse('lists/individuals-table', [ |
||
213 | 'individuals' => $ancestors, |
||
214 | 'sosa' => true, |
||
215 | 'tree' => $tree, |
||
216 | ]); |
||
217 | |||
218 | case self::CHART_STYLE_FAMILIES: |
||
219 | $families = []; |
||
220 | |||
221 | foreach ($ancestors as $individual) { |
||
222 | foreach ($individual->childFamilies() as $family) { |
||
223 | $families[$family->xref()] = $family; |
||
224 | } |
||
225 | } |
||
226 | |||
227 | return $this->viewResponse('lists/families-table', [ |
||
228 | 'families' => $families, |
||
229 | 'tree' => $tree, |
||
230 | ]); |
||
231 | } |
||
232 | } |
||
233 | |||
234 | $ajax_url = $this->chartUrl($individual, [ |
||
235 | 'ajax' => true, |
||
236 | 'generations' => $generations, |
||
237 | 'style' => $style, |
||
238 | 'xref' => $xref, |
||
239 | ]); |
||
240 | |||
241 | return $this->viewResponse('modules/ancestors-chart/page', [ |
||
242 | 'ajax_url' => $ajax_url, |
||
243 | 'generations' => $generations, |
||
244 | 'individual' => $individual, |
||
245 | 'maximum_generations' => self::MAXIMUM_GENERATIONS, |
||
246 | 'minimum_generations' => self::MINIMUM_GENERATIONS, |
||
247 | 'module' => $this->name(), |
||
248 | 'style' => $style, |
||
249 | 'styles' => $this->styles(), |
||
250 | 'title' => $this->chartTitle($individual), |
||
251 | ]); |
||
268 |