Conditions | 10 |
Paths | 2 |
Total Lines | 45 |
Code Lines | 25 |
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 |
||
50 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
51 | { |
||
52 | $tree = $request->getAttribute('tree'); |
||
53 | assert($tree instanceof Tree); |
||
54 | |||
55 | $xref = $request->getAttribute('xref'); |
||
56 | $record = GedcomRecord::getInstance($xref, $tree); |
||
57 | |||
58 | Auth::checkRecordAccess($record, true); |
||
59 | |||
60 | if ($record && Auth::isEditor($record->tree()) && $record->canShow() && $record->canEdit()) { |
||
61 | // Delete links to this record |
||
62 | foreach ($record->linkingRecords() as $linker) { |
||
63 | $old_gedcom = $linker->gedcom(); |
||
64 | $new_gedcom = $this->removeLinks($old_gedcom, $record->xref()); |
||
65 | if ($old_gedcom !== $new_gedcom) { |
||
66 | // If we have removed a link from a family to an individual, and it has only one member |
||
67 | if (preg_match('/^0 @' . Gedcom::REGEX_XREF . '@ FAM/', $new_gedcom) && preg_match_all('/\n1 (HUSB|WIFE|CHIL) @(' . Gedcom::REGEX_XREF . ')@/', $new_gedcom, $match) == 1) { |
||
68 | // Delete the family |
||
69 | $family = GedcomRecord::getInstance($xref, $tree); |
||
70 | /* I18N: %s is the name of a family group, e.g. “Husband name + Wife name” */ |
||
71 | FlashMessages::addMessage(I18N::translate('The family “%s” has been deleted because it only has one member.', $family->fullName())); |
||
72 | $family->deleteRecord(); |
||
73 | // Delete any remaining link to this family |
||
74 | if ($match) { |
||
75 | $relict = GedcomRecord::getInstance($match[2][0], $tree); |
||
76 | $new_gedcom = $relict->gedcom(); |
||
77 | $new_gedcom = $this->removeLinks($new_gedcom, $linker->xref()); |
||
78 | $relict->updateRecord($new_gedcom, false); |
||
79 | /* I18N: %s are names of records, such as sources, repositories or individuals */ |
||
80 | FlashMessages::addMessage(I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $relict->fullName(), $family->fullName())); |
||
81 | } |
||
82 | } else { |
||
83 | // Remove links from $linker to $record |
||
84 | /* I18N: %s are names of records, such as sources, repositories or individuals */ |
||
85 | FlashMessages::addMessage(I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $linker->fullName(), $record->fullName())); |
||
86 | $linker->updateRecord($new_gedcom, false); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | // Delete the record itself |
||
91 | $record->deleteRecord(); |
||
92 | } |
||
93 | |||
94 | return response(); |
||
95 | } |
||
116 |