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