Conditions | 9 |
Paths | 16 |
Total Lines | 68 |
Code Lines | 52 |
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 |
||
76 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
77 | { |
||
78 | $tree = $request->getAttribute('tree'); |
||
79 | assert($tree instanceof Tree, new InvalidArgumentException()); |
||
80 | |||
81 | $url = $request->getQueryParams()['url'] ?? route('tree-page', ['tree' => $tree->name()]); |
||
82 | |||
83 | $rows = DB::table('change') |
||
84 | ->join('user', 'user.user_id', '=', 'change.user_id') |
||
85 | ->join('gedcom', 'gedcom.gedcom_id', '=', 'change.gedcom_id') |
||
86 | ->where('status', '=', 'pending') |
||
87 | ->orderBy('change.gedcom_id') |
||
88 | ->orderBy('change.xref') |
||
89 | ->orderBy('change.change_id') |
||
90 | ->select(['change.*', 'user.user_name', 'user.real_name', 'gedcom_name']) |
||
91 | ->get(); |
||
92 | |||
93 | $changes = []; |
||
94 | foreach ($rows as $row) { |
||
95 | $row->change_time = Carbon::make($row->change_time); |
||
96 | |||
97 | $change_tree = $this->tree_service->all()->get($row->gedcom_name); |
||
98 | |||
99 | preg_match('/^0 (?:@' . Gedcom::REGEX_XREF . '@ )?(' . Gedcom::REGEX_TAG . ')/', $row->old_gedcom . $row->new_gedcom, $match); |
||
100 | |||
101 | switch ($match[1]) { |
||
102 | case 'INDI': |
||
103 | $row->record = new Individual($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
104 | break; |
||
105 | case 'FAM': |
||
106 | $row->record = new Family($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
107 | break; |
||
108 | case 'SOUR': |
||
109 | $row->record = new Source($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
110 | break; |
||
111 | case 'REPO': |
||
112 | $row->record = new Repository($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
113 | break; |
||
114 | case 'OBJE': |
||
115 | $row->record = new Media($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
116 | break; |
||
117 | case 'NOTE': |
||
118 | $row->record = new Note($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
119 | break; |
||
120 | default: |
||
121 | $row->record = new GedcomRecord($row->xref, $row->old_gedcom, $row->new_gedcom, $change_tree); |
||
122 | break; |
||
123 | } |
||
124 | |||
125 | $changes[$row->gedcom_id][$row->xref][] = $row; |
||
126 | } |
||
127 | |||
128 | $title = I18N::translate('Pending changes'); |
||
129 | |||
130 | // If the current tree has changes, activate that tab. Otherwise activate the first tab. |
||
131 | if (($changes[$tree->id()] ?? []) === []) { |
||
132 | reset($changes); |
||
133 | $active_tree_id = key($changes); |
||
134 | } else { |
||
135 | $active_tree_id = $tree->id(); |
||
136 | } |
||
137 | |||
138 | return $this->viewResponse('pending-changes-page', [ |
||
139 | 'active_tree_id' => $active_tree_id, |
||
140 | 'changes' => $changes, |
||
141 | 'title' => $title, |
||
142 | 'tree' => $tree, |
||
143 | 'url' => $url, |
||
144 | ]); |
||
147 |