Conditions | 6 |
Paths | 6 |
Total Lines | 71 |
Code Lines | 50 |
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 | $tree = $request->getAttribute('tree'); |
||
173 | $user = $request->getAttribute('user'); |
||
174 | $xref = $request->getAttribute('xref'); |
||
175 | $style = $request->getAttribute('style'); |
||
176 | $generations = (int) $request->getAttribute('generations'); |
||
177 | $ajax = $request->getQueryParams()['ajax'] ?? ''; |
||
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 | switch ($style) { |
||
200 | case self::CHART_STYLE_TREE: |
||
201 | return $this->viewResponse('modules/descendancy_chart/tree', [ |
||
202 | 'individual' => $individual, |
||
203 | 'generations' => $generations, |
||
204 | 'daboville' => '1', |
||
205 | ]); |
||
206 | |||
207 | case self::CHART_STYLE_INDIVIDUALS: |
||
208 | return $this->viewResponse('lists/individuals-table', [ |
||
209 | 'individuals' => $this->chart_service->descendants($individual, $generations - 1), |
||
210 | 'sosa' => false, |
||
211 | 'tree' => $tree, |
||
212 | ]); |
||
213 | |||
214 | case self::CHART_STYLE_FAMILIES: |
||
215 | $families = $this->chart_service->descendantFamilies($individual, $generations - 1); |
||
216 | |||
217 | return $this->viewResponse('lists/families-table', [ |
||
218 | 'families' => $families, |
||
219 | 'tree' => $tree, |
||
220 | ]); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | $ajax_url = $this->chartUrl($individual, [ |
||
225 | 'generations' => $generations, |
||
226 | 'style' => $style, |
||
227 | 'ajax' => true, |
||
228 | ]); |
||
229 | |||
230 | return $this->viewResponse('modules/descendancy_chart/page', [ |
||
231 | 'ajax_url' => $ajax_url, |
||
232 | 'style' => $style, |
||
233 | 'styles' => $this->styles(), |
||
234 | 'default_generations' => self::DEFAULT_GENERATIONS, |
||
235 | 'generations' => $generations, |
||
236 | 'individual' => $individual, |
||
237 | 'maximum_generations' => self::MAXIMUM_GENERATIONS, |
||
238 | 'minimum_generations' => self::MINIMUM_GENERATIONS, |
||
239 | 'module' => $this->name(), |
||
240 | 'title' => $this->chartTitle($individual), |
||
241 | ]); |
||
258 |