| Conditions | 16 |
| Paths | 336 |
| Total Lines | 87 |
| Code Lines | 65 |
| 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 |
||
| 152 | private function formatNameRecord($n, Fact $fact) { |
||
| 153 | $individual = $fact->getParent(); |
||
| 154 | |||
| 155 | // Create a dummy record, so we can extract the formatted NAME value from it. |
||
| 156 | $dummy = new Individual( |
||
| 157 | 'xref', |
||
| 158 | "0 @xref@ INDI\n1 DEAT Y\n" . $fact->getGedcom(), |
||
| 159 | null, |
||
| 160 | $individual->getTree() |
||
| 161 | ); |
||
| 162 | $dummy->setPrimaryName(0); // Make sure we use the name from "1 NAME" |
||
| 163 | |||
| 164 | $container_class = 'card'; |
||
| 165 | $content_class = 'collapse'; |
||
| 166 | $aria = 'false'; |
||
| 167 | |||
| 168 | if ($n === 0) { |
||
| 169 | $content_class = 'collapse show'; |
||
| 170 | $aria = 'true'; |
||
| 171 | } |
||
| 172 | if ($fact->isPendingDeletion()) { |
||
| 173 | $container_class .= ' old'; |
||
| 174 | } elseif ($fact->isPendingAddition()) { |
||
| 175 | $container_class .= ' new'; |
||
| 176 | } |
||
| 177 | |||
| 178 | ob_start(); |
||
| 179 | echo '<dl><dt class="label">', I18N::translate('Name'), '</dt>'; |
||
| 180 | echo '<dd class="field">', $dummy->getFullName(), '</dd>'; |
||
| 181 | $ct = preg_match_all('/\n2 (\w+) (.*)/', $fact->getGedcom(), $nmatch, PREG_SET_ORDER); |
||
| 182 | for ($i = 0; $i < $ct; $i++) { |
||
| 183 | $tag = $nmatch[$i][1]; |
||
| 184 | if ($tag != 'SOUR' && $tag != 'NOTE' && $tag != 'SPFX') { |
||
| 185 | echo '<dt class="label">', GedcomTag::getLabel($tag, $individual), '</dt>'; |
||
| 186 | echo '<dd class="field">'; // Before using dir="auto" on this field, note that Gecko treats this as an inline element but WebKit treats it as a block element |
||
| 187 | if (isset($nmatch[$i][2])) { |
||
| 188 | $name = e($nmatch[$i][2]); |
||
| 189 | $name = str_replace('/', '', $name); |
||
| 190 | $name = preg_replace('/(\S*)\*/', '<span class="starredname">\\1</span>', $name); |
||
| 191 | switch ($tag) { |
||
| 192 | case 'TYPE': |
||
| 193 | echo GedcomCodeName::getValue($name, $individual); |
||
| 194 | break; |
||
| 195 | case 'SURN': |
||
| 196 | // The SURN field is not necessarily the surname. |
||
| 197 | // Where it is not a substring of the real surname, show it after the real surname. |
||
| 198 | $surname = e($dummy->getAllNames()[0]['surname']); |
||
| 199 | $surns = preg_replace('/, */', ' ', $nmatch[$i][2]); |
||
| 200 | if (strpos($dummy->getAllNames()[0]['surname'], $surns) !== false) { |
||
| 201 | echo '<span dir="auto">' . $surname . '</span>'; |
||
| 202 | } else { |
||
| 203 | echo I18N::translate('%1$s (%2$s)', '<span dir="auto">' . $surname . '</span>', '<span dir="auto">' . $name . '</span>'); |
||
| 204 | } |
||
| 205 | break; |
||
| 206 | default: |
||
| 207 | echo '<span dir="auto">' . $name . '</span>'; |
||
| 208 | break; |
||
| 209 | } |
||
| 210 | } |
||
| 211 | echo '</dd>'; |
||
| 212 | echo '</dl>'; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | if (preg_match("/\n2 SOUR/", $fact->getGedcom())) { |
||
| 216 | echo '<div id="indi_sour" class="clearfloat">', FunctionsPrintFacts::printFactSources($fact->getGedcom(), 2), '</div>'; |
||
| 217 | } |
||
| 218 | if (preg_match("/\n2 NOTE/", $fact->getGedcom())) { |
||
| 219 | echo '<div id="indi_note" class="clearfloat">', FunctionsPrint::printFactNotes($fact->getGedcom(), 2), '</div>'; |
||
| 220 | } |
||
| 221 | $content = ob_get_clean(); |
||
| 222 | |||
| 223 | if ($individual->canEdit() && !$fact->isPendingDeletion()) { |
||
| 224 | $edit_links = |
||
| 225 | FontAwesome::linkIcon('delete', I18N::translate('Delete this name'), ['class' => 'btn btn-link', 'href' => '#', 'onclick' => 'return delete_fact("' . I18N::translate('Are you sure you want to delete this fact?') . '", "' . $individual->getXref() . '", "' . $fact->getFactId() . '");']) . |
||
| 226 | FontAwesome::linkIcon('edit', I18N::translate('Edit the name'), ['class' => 'btn btn-link', 'href' => 'edit_interface.php?action=editname&xref=' . $individual->getXref() . '&fact_id=' . $fact->getFactId() . '&ged=' . $individual->getTree()->getNameHtml()]); |
||
| 227 | } else { |
||
| 228 | $edit_links = ''; |
||
| 229 | } |
||
| 230 | |||
| 231 | return ' |
||
| 232 | <div class="' . $container_class . '"> |
||
| 233 | <div class="card-header" role="tab" id="name-header-' . $n . '"> |
||
| 234 | <a data-toggle="collapse" data-parent="#individual-names" href="#name-content-' . $n . '" aria-expanded="' . $aria . '" aria-controls="name-content-' . $n . '">' . $dummy->getFullName() . '</a> |
||
| 235 | ' . $edit_links . ' |
||
| 236 | </div> |
||
| 237 | <div id="name-content-' . $n . '" class="' . $content_class . '" role="tabpanel" aria-labelledby="name-header-' . $n . '"> |
||
| 238 | <div class="card-body">' . $content . '</div> |
||
| 239 | </div> |
||
| 320 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.