| Conditions | 12 |
| Paths | 16 |
| Total Lines | 67 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 108 | public function labelValue(string $value, Tree $tree): string |
||
| 109 | { |
||
| 110 | $id = Registry::idFactory()->id(); |
||
| 111 | $expanded = $tree->getPreference('EXPAND_NOTES') === '1'; |
||
| 112 | |||
| 113 | // A note structure can contain an inline note or a linked to a shared note. |
||
| 114 | if (preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $value, $match) === 1) { |
||
| 115 | $note = Registry::noteFactory()->make($match[1], $tree); |
||
| 116 | |||
| 117 | if ($note === null) { |
||
| 118 | return parent::labelValue($value, $tree); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (!$note->canShow()) { |
||
| 122 | return ''; |
||
| 123 | } |
||
| 124 | |||
| 125 | $label = '<span class="label">' . I18N::translate('Shared note') . '</span>'; |
||
| 126 | $value = $note->getNote(); |
||
| 127 | $html = $this->valueFormatted($value, $tree); |
||
| 128 | $first_line = '<a href="' . e($note->url()) . '">' . $note->fullName() . '</a>'; |
||
| 129 | |||
| 130 | // Shared note where the title is the same as the text |
||
| 131 | if ($html === '<p>' . strip_tags($note->fullName()) . '</p>') { |
||
| 132 | $value = '<a href="' . e($note->url()) . '">' . strip_tags($html) . '</a>'; |
||
| 133 | |||
| 134 | return '<div>' . I18N::translate('%1$s: %2$s', $label, $value) . '</div>'; |
||
| 135 | } |
||
| 136 | |||
| 137 | return |
||
| 138 | '<div class="wt-text-overflow-elipsis">' . |
||
| 139 | '<button type="button" class="btn btn-text p-0" href="#' . e($id) . '" data-bs-toggle="collapse" aria-controls="' . e($id) . '" aria-expanded="' . ($expanded ? 'true' : 'false') . '">' . |
||
| 140 | view('icons/expand') . |
||
| 141 | view('icons/collapse') . |
||
| 142 | '</button> ' . |
||
| 143 | '<span class="label">' . $label . ':</span> ' . $first_line . |
||
| 144 | '</div>' . |
||
| 145 | '<div id="' . e($id) . '" class="ps-4 collapse ' . ($expanded ? 'show' : '') . '">' . |
||
| 146 | $html . |
||
| 147 | '</div>'; |
||
| 148 | } |
||
| 149 | |||
| 150 | $label = '<span class="label">' . I18N::translate('Note') . '</span>'; |
||
| 151 | $html = $this->valueFormatted($value, $tree); |
||
| 152 | |||
| 153 | // Inline note with only one paragraph and inline markup? |
||
| 154 | if ($html === strip_tags($html, ['a', 'em', 'p', 'strong']) && substr_count($html, '<p>') === 1) { |
||
| 155 | $html = strip_tags($html, ['a', 'em', 'strong']); |
||
| 156 | $value = '<span class="ut">' . $html . '</span>'; |
||
| 157 | |||
| 158 | return '<div>' . I18N::translate('%1$s: %2$s', $label, $value) . '</div>'; |
||
| 159 | } |
||
| 160 | |||
| 161 | $value = e(Note::firstLineOfTextFromHtml($html)); |
||
| 162 | $value = '<span class="ut collapse ' . ($expanded ? '' : 'show') . ' ' . e($id) . '">' . $value . '</span>'; |
||
| 163 | |||
| 164 | return |
||
| 165 | '<div class="wt-text-overflow-elipsis">' . |
||
| 166 | '<button type="button" class="btn btn-text p-0" href="#" data-bs-target=".' . e($id) . '" data-bs-toggle="collapse" aria-controls="' . e($id) . '" aria-expanded="' . ($expanded ? 'true' : 'false') . '">' . |
||
| 167 | view('icons/expand') . |
||
| 168 | view('icons/collapse') . |
||
| 169 | '</button> ' . |
||
| 170 | I18N::translate('%1$s: %2$s', $label, $value) . |
||
| 171 | '</div>' . |
||
| 172 | '<div class="ps-4 collapse ' . ($expanded ? 'show' : '') . ' ' . e($id) . '">' . |
||
| 173 | $html . |
||
| 174 | '</div>'; |
||
| 175 | } |
||
| 198 |