| Conditions | 16 |
| Paths | 16 |
| Total Lines | 106 |
| Code Lines | 82 |
| 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 |
||
| 186 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 187 | { |
||
| 188 | $topic = $request->getAttribute('topic'); |
||
| 189 | |||
| 190 | $dmy = I18N::language()->dateOrder(); |
||
| 191 | |||
| 192 | switch ($topic) { |
||
| 193 | case 'DATE': |
||
| 194 | switch ($dmy) { |
||
| 195 | case 'YMD': |
||
| 196 | $date_shortcuts = self::DATE_SHORTCUTS + self::YMD_SHORTCUTS; |
||
| 197 | break; |
||
| 198 | case 'MDY': |
||
| 199 | $date_shortcuts = self::DATE_SHORTCUTS + self::MDY_SHORTCUTS; |
||
| 200 | break; |
||
| 201 | case 'DMY': |
||
| 202 | default: |
||
| 203 | $date_shortcuts = self::DATE_SHORTCUTS + self::DMY_SHORTCUTS; |
||
| 204 | break; |
||
| 205 | } |
||
| 206 | |||
| 207 | $title = I18N::translate('Date'); |
||
| 208 | $text = view('help/date', [ |
||
| 209 | 'date_dates' => $this->formatDates(array_keys($date_shortcuts)), |
||
| 210 | 'date_shortcuts' => $date_shortcuts, |
||
| 211 | 'date_period_dates' => $this->formatDates(array_keys(self::DATE_PERIOD_SHORTCUTS)), |
||
| 212 | 'date_period_shortcuts' => self::DATE_PERIOD_SHORTCUTS, |
||
| 213 | 'date_range_dates' => $this->formatDates(array_keys(self::DATE_RANGE_SHORTCUTS)), |
||
| 214 | 'date_range_shortcuts' => self::DATE_RANGE_SHORTCUTS, |
||
| 215 | 'french_dates' => $this->formatDates(self::FRENCH_DATES), |
||
| 216 | 'hijri_dates' => $this->formatDates(self::HIJRI_DATES), |
||
| 217 | 'jalali_dates' => $this->formatDates(self::JALALI_DATES), |
||
| 218 | 'jewish_dates' => $this->formatDates(self::JEWISH_DATES), |
||
| 219 | 'julian_dates' => $this->formatDates(self::JULIAN_DATES), |
||
| 220 | ]); |
||
| 221 | break; |
||
| 222 | |||
| 223 | case 'NAME': |
||
| 224 | $title = I18N::translate('Name'); |
||
| 225 | $text = view('help/name'); |
||
| 226 | break; |
||
| 227 | |||
| 228 | case 'SURN': |
||
| 229 | $title = I18N::translate('Surname'); |
||
| 230 | $text = view('help/surname'); |
||
| 231 | break; |
||
| 232 | |||
| 233 | case 'OBJE': |
||
| 234 | $title = I18N::translate('Media object'); |
||
| 235 | $text = view('help/media-object'); |
||
| 236 | break; |
||
| 237 | |||
| 238 | case 'PLAC': |
||
| 239 | $title = I18N::translate('Place'); |
||
| 240 | $text = view('help/place'); |
||
| 241 | break; |
||
| 242 | |||
| 243 | case 'RESN': |
||
| 244 | $title = I18N::translate('Restriction'); |
||
| 245 | $text = view('help/restriction'); |
||
| 246 | break; |
||
| 247 | |||
| 248 | case 'ROMN': |
||
| 249 | $title = I18N::translate('Romanized'); |
||
| 250 | $text = view('help/romanized'); |
||
| 251 | break; |
||
| 252 | |||
| 253 | case '_HEB': |
||
| 254 | $title = I18N::translate('Hebrew'); |
||
| 255 | $text = view('help/hebrew'); |
||
| 256 | break; |
||
| 257 | |||
| 258 | case 'data-fixes': |
||
| 259 | $title = I18N::translate('Data fixes'); |
||
| 260 | $text = view('help/data-fixes'); |
||
| 261 | break; |
||
| 262 | |||
| 263 | case 'edit_SOUR_EVEN': |
||
| 264 | $title = I18N::translate('Associate events with this source'); |
||
| 265 | $text = view('help/source-events'); |
||
| 266 | break; |
||
| 267 | |||
| 268 | case 'pending_changes': |
||
| 269 | $title = I18N::translate('Pending changes'); |
||
| 270 | $text = view('help/pending-changes', [ |
||
| 271 | 'is_admin' => Auth::isAdmin(), |
||
| 272 | ]); |
||
| 273 | break; |
||
| 274 | |||
| 275 | case 'relationship-privacy': |
||
| 276 | $title = I18N::translate('Restrict to immediate family'); |
||
| 277 | $text = view('help/relationship-privacy'); |
||
| 278 | break; |
||
| 279 | |||
| 280 | default: |
||
| 281 | $title = I18N::translate('Help'); |
||
| 282 | $text = I18N::translate('The help text has not been written for this item.'); |
||
| 283 | break; |
||
| 284 | } |
||
| 285 | |||
| 286 | $html = view('modals/help', [ |
||
| 287 | 'title' => $title, |
||
| 288 | 'text' => $text, |
||
| 289 | ]); |
||
| 290 | |||
| 291 | return Registry::responseFactory()->response($html); |
||
| 292 | } |
||
| 316 |