Conditions | 6 |
Paths | 16 |
Total Lines | 58 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
47 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
48 | { |
||
49 | $tree = $request->getAttribute('tree'); |
||
50 | assert($tree instanceof Tree); |
||
51 | |||
52 | $user = $request->getAttribute('user'); |
||
53 | assert($user instanceof User); |
||
54 | |||
55 | $associates = (bool) ($request->getQueryParams()['associates'] ?? false); |
||
56 | |||
57 | if ($associates) { |
||
58 | $links = ['FAMS', 'FAMC', 'ASSO', '_ASSO']; |
||
59 | } else { |
||
60 | $links = ['FAMS', 'FAMC']; |
||
61 | } |
||
62 | |||
63 | $rows = DB::table('link') |
||
64 | ->where('l_file', '=', $tree->id()) |
||
65 | ->whereIn('l_type', $links) |
||
66 | ->select(['l_from', 'l_to']) |
||
67 | ->get(); |
||
68 | |||
69 | $graph = []; |
||
70 | |||
71 | foreach ($rows as $row) { |
||
72 | $graph[$row->l_from][$row->l_to] = 1; |
||
73 | $graph[$row->l_to][$row->l_from] = 1; |
||
74 | } |
||
75 | |||
76 | $algorithm = new ConnectedComponent($graph); |
||
77 | $components = $algorithm->findConnectedComponents(); |
||
78 | $root = $tree->significantIndividual($user); |
||
79 | $xref = $root->xref(); |
||
80 | |||
81 | /** @var Individual[][] */ |
||
82 | $individual_groups = []; |
||
83 | |||
84 | foreach ($components as $component) { |
||
85 | if (!in_array($xref, $component, true)) { |
||
86 | $individuals = []; |
||
87 | foreach ($component as $xref) { |
||
88 | $individuals[] = Individual::getInstance($xref, $tree); |
||
89 | } |
||
90 | // The database query may return pending additions/deletions, which may not exist. |
||
91 | $individual_groups[] = array_filter($individuals); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | $title = I18N::translate('Find unrelated individuals') . ' — ' . e($tree->title()); |
||
96 | |||
97 | $this->layout = 'layouts/administration'; |
||
98 | |||
99 | return $this->viewResponse('admin/trees-unconnected', [ |
||
100 | 'associates' => $associates, |
||
101 | 'root' => $root, |
||
102 | 'individual_groups' => $individual_groups, |
||
103 | 'title' => $title, |
||
104 | 'tree' => $tree, |
||
105 | ]); |
||
108 |