Conditions | 12 |
Paths | 12 |
Total Lines | 53 |
Code Lines | 32 |
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 |
||
66 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
67 | { |
||
68 | $tree = $request->getAttribute('tree'); |
||
69 | assert($tree instanceof Tree); |
||
70 | |||
71 | $xref = $request->getAttribute('xref'); |
||
72 | assert(is_string($xref)); |
||
73 | |||
74 | $fact_id = $request->getAttribute('fact_id') ?? ''; |
||
75 | assert(is_string($fact_id)); |
||
76 | |||
77 | $record = Registry::gedcomRecordFactory()->make($xref, $tree); |
||
78 | $record = Auth::checkRecordAccess($record, true); |
||
79 | |||
80 | $params = (array) $request->getParsedBody(); |
||
81 | $keep_chan = (bool) ($params['keep_chan'] ?? false); |
||
82 | $levels = $params['levels']; |
||
83 | $tags = $params['tags']; |
||
84 | $values = $params['values']; |
||
85 | |||
86 | $gedcom = $this->gedcom_edit_service->editLinesToGedcom($record::RECORD_TYPE, $levels, $tags, $values); |
||
87 | |||
88 | $census_assistant = $this->module_service->findByInterface(CensusAssistantModule::class)->first(); |
||
89 | |||
90 | if ($census_assistant instanceof CensusAssistantModule && $record instanceof Individual) { |
||
91 | $gedcom = $census_assistant->updateCensusAssistant($request, $record, $fact_id, $gedcom, $keep_chan); |
||
92 | $pid_array = $params['pid_array'] ?? ''; |
||
93 | if ($pid_array !== '') { |
||
94 | foreach (explode(',', $pid_array) as $pid) { |
||
95 | if ($pid !== $xref) { |
||
96 | $individual = Registry::individualFactory()->make($pid, $tree); |
||
97 | if ($individual instanceof Individual && $individual->canEdit()) { |
||
98 | $individual->updateFact('', $gedcom, !$keep_chan); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | |||
105 | if ($fact_id === 'new') { |
||
106 | // Add a new fact |
||
107 | $record->updateFact('', $gedcom, !$keep_chan); |
||
108 | } else { |
||
109 | // Update (only the first copy of) an existing fact |
||
110 | foreach ($record->facts([], false, null, true) as $fact) { |
||
111 | if ($fact->id() === $fact_id && $fact->canEdit()) { |
||
112 | $record->updateFact($fact_id, $gedcom, !$keep_chan); |
||
113 | break; |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | |||
118 | return redirect($params['url'] ?? $record->url()); |
||
119 | } |
||
121 |