| Conditions | 21 | 
| Paths | 64 | 
| Total Lines | 89 | 
| Code Lines | 53 | 
| 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  | 
            ||
| 58 | public function updateFact(ServerRequestInterface $request): ResponseInterface  | 
            ||
| 59 |     { | 
            ||
| 60 |         $tree = $request->getAttribute('tree'); | 
            ||
| 61 | assert($tree instanceof Tree);  | 
            ||
| 62 | |||
| 63 |         $xref    = $request->getAttribute('xref'); | 
            ||
| 64 | $fact_id = $request->getParsedBody()['fact_id'] ?? '';  | 
            ||
| 65 | |||
| 66 | $record = GedcomRecord::getInstance($xref, $tree);  | 
            ||
| 67 | Auth::checkRecordAccess($record, true);  | 
            ||
| 68 | |||
| 69 | $keep_chan = (bool) ($request->getParsedBody()['keep_chan'] ?? false);  | 
            ||
| 70 | |||
| 71 | $this->glevels = $request->getParsedBody()['glevels'];  | 
            ||
| 72 | $this->tag = $request->getParsedBody()['tag'];  | 
            ||
| 73 | $this->text = $request->getParsedBody()['text'];  | 
            ||
| 74 | $this->islink = $request->getParsedBody()['islink'];  | 
            ||
| 75 | |||
| 76 | // If the fact has a DATE or PLAC, then delete any value of Y  | 
            ||
| 77 |         if ($this->text[0] === 'Y') { | 
            ||
| 78 |             foreach ($this->tag as $n => $value) { | 
            ||
| 79 |                 if ($this->glevels[$n] == 2 && ($value === 'DATE' || $value === 'PLAC') && $this->text[$n] !== '') { | 
            ||
| 80 | $this->text[0] = '';  | 
            ||
| 81 | break;  | 
            ||
| 82 | }  | 
            ||
| 83 | }  | 
            ||
| 84 | }  | 
            ||
| 85 | |||
| 86 | $newged = '';  | 
            ||
| 87 | |||
| 88 | $NAME = $request->getParsedBody()['NAME'] ?? '';  | 
            ||
| 89 | |||
| 90 |         if ($NAME !== '') { | 
            ||
| 91 | $newged .= "\n1 NAME " . $NAME;  | 
            ||
| 92 | $name_facts = [  | 
            ||
| 93 | 'TYPE',  | 
            ||
| 94 | 'NPFX',  | 
            ||
| 95 | 'GIVN',  | 
            ||
| 96 | 'NICK',  | 
            ||
| 97 | 'SPFX',  | 
            ||
| 98 | 'SURN',  | 
            ||
| 99 | 'NSFX',  | 
            ||
| 100 | ];  | 
            ||
| 101 |             foreach ($name_facts as $name_fact) { | 
            ||
| 102 | $NAME_FACT = $request->getParsedBody()[$name_fact] ?? '';  | 
            ||
| 103 |                 if ($NAME_FACT !== '') { | 
            ||
| 104 | $newged .= "\n2 " . $name_fact . ' ' . $NAME_FACT;  | 
            ||
| 105 | }  | 
            ||
| 106 | }  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 | $newged = $this->handleUpdates($newged);  | 
            ||
| 110 | |||
| 111 | // Add new names after existing names  | 
            ||
| 112 |         if ($NAME !== '') { | 
            ||
| 113 |             preg_match_all('/[_0-9A-Z]+/', $tree->getPreference('ADVANCED_NAME_FACTS'), $match); | 
            ||
| 114 | $name_facts = array_unique(array_merge(['_MARNM'], $match[0]));  | 
            ||
| 115 |             foreach ($name_facts as $name_fact) { | 
            ||
| 116 | $NAME_FACT = $request->getParsedBody()[$name_fact] ?? '';  | 
            ||
| 117 | // Ignore advanced facts that duplicate standard facts.  | 
            ||
| 118 |                 if ($NAME_FACT !== '' && !in_array($name_fact, ['TYPE', 'NPFX', 'GIVN', 'NICK', 'SPFX', 'SURN', 'NSFX'], true)) { | 
            ||
| 119 | $newged .= "\n2 " . $name_fact . ' ' . $NAME_FACT;  | 
            ||
| 120 | }  | 
            ||
| 121 | }  | 
            ||
| 122 | }  | 
            ||
| 123 | |||
| 124 | $newged = trim($newged); // Remove leading newline  | 
            ||
| 125 | |||
| 126 | $census_assistant = $this->module_service->findByInterface(CensusAssistantModule::class)->first();  | 
            ||
| 127 |         if ($census_assistant instanceof CensusAssistantModule && $record instanceof Individual) { | 
            ||
| 128 | $newged = $census_assistant->updateCensusAssistant($request, $record, $fact_id, $newged, $keep_chan);  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 131 | $record->updateFact($fact_id, $newged, !$keep_chan);  | 
            ||
| 132 | |||
| 133 | // For the GEDFact_assistant module  | 
            ||
| 134 | $pid_array = $request->getParsedBody()['pid_array'] ?? '';  | 
            ||
| 135 |         if ($pid_array !== '') { | 
            ||
| 136 |             foreach (explode(',', $pid_array) as $pid) { | 
            ||
| 137 |                 if ($pid !== $xref) { | 
            ||
| 138 | $indi = Individual::getInstance($pid, $tree);  | 
            ||
| 139 |                     if ($indi && $indi->canEdit()) { | 
            ||
| 140 | $indi->updateFact($fact_id, $newged, !$keep_chan);  | 
            ||
| 141 | }  | 
            ||
| 142 | }  | 
            ||
| 143 | }  | 
            ||
| 144 | }  | 
            ||
| 145 | |||
| 146 | return redirect($record->url());  | 
            ||
| 147 | }  | 
            ||
| 149 |