| Conditions | 17 | 
| Paths | 128 | 
| Total Lines | 138 | 
| Code Lines | 101 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 3 | ||
| 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 | ||
| 330 | public function formAlter($mode, $msg = ''): void | ||
| 331 |     { | ||
| 332 | $data = $this->misc->getDatabaseAccessor(); | ||
| 333 | |||
| 334 | $this->coalesceArr($_REQUEST, 'username', []); | ||
| 335 | |||
| 336 | $this->coalesceArr($_REQUEST, 'groupname', []); | ||
| 337 | |||
| 338 | $this->coalesceArr($_REQUEST, 'privilege', []); | ||
| 339 | |||
| 340 | // Get users from the database | ||
| 341 | $users = $data->getUsers(); | ||
| 342 | // Get groups from the database | ||
| 343 | $groups = $data->getGroups(); | ||
| 344 | |||
| 345 | $this->printTrail($_REQUEST['subject']); | ||
| 346 | |||
| 347 | $this->printTitle($this->lang['str' . $mode], 'pg.privilege.' . $mode); | ||
| 348 | |||
| 349 | $this->printMsg($msg); | ||
| 350 | |||
| 351 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/privileges" method="post">' . \PHP_EOL; | ||
| 352 | echo '<table>' . \PHP_EOL; | ||
| 353 | echo \sprintf( | ||
| 354 | '<tr><th class="data left">%s</th>', | ||
| 355 | $this->lang['strusers'] | ||
| 356 | ) . \PHP_EOL; | ||
| 357 | echo '<td class="data1"><select name="username[]" multiple="multiple" size="', \min(6, $users->recordCount()), '">' . \PHP_EOL; | ||
| 358 | |||
| 359 |         while (!$users->EOF) { | ||
| 360 | $uname = \htmlspecialchars($users->fields['usename']); | ||
| 361 | echo \sprintf( | ||
| 362 | '<option value="%s"', | ||
| 363 | $uname | ||
| 364 | ), | ||
| 365 | \in_array($users->fields['usename'], $_REQUEST['username'], true) ? ' selected="selected"' : '', \sprintf( | ||
| 366 | '>%s</option>', | ||
| 367 | $uname | ||
| 368 | ) . \PHP_EOL; | ||
| 369 | $users->moveNext(); | ||
| 370 | } | ||
| 371 | echo '</select></td></tr>' . \PHP_EOL; | ||
| 372 | echo \sprintf( | ||
| 373 | '<tr><th class="data left">%s</th>', | ||
| 374 | $this->lang['strgroups'] | ||
| 375 | ) . \PHP_EOL; | ||
| 376 | echo '<td class="data1">' . \PHP_EOL; | ||
| 377 | echo '<input type="checkbox" id="public" name="public"', (isset($_REQUEST['public']) ? ' checked="checked"' : ''), ' /><label for="public">PUBLIC</label>' . \PHP_EOL; | ||
| 378 | // Only show groups if there are groups! | ||
| 379 |         if (0 < $groups->recordCount()) { | ||
| 380 | echo '<br /><select name="groupname[]" multiple="multiple" size="', \min(6, $groups->recordCount()), '">' . \PHP_EOL; | ||
| 381 | |||
| 382 |             while (!$groups->EOF) { | ||
| 383 | $gname = \htmlspecialchars($groups->fields['groname']); | ||
| 384 | echo \sprintf( | ||
| 385 | '<option value="%s"', | ||
| 386 | $gname | ||
| 387 | ), | ||
| 388 | \in_array($groups->fields['groname'], $_REQUEST['groupname'], true) ? ' selected="selected"' : '', \sprintf( | ||
| 389 | '>%s</option>', | ||
| 390 | $gname | ||
| 391 | ) . \PHP_EOL; | ||
| 392 | $groups->moveNext(); | ||
| 393 | } | ||
| 394 | echo '</select>' . \PHP_EOL; | ||
| 395 | } | ||
| 396 | echo '</td></tr>' . \PHP_EOL; | ||
| 397 | echo \sprintf( | ||
| 398 | '<tr><th class="data left required">%s</th>', | ||
| 399 | $this->lang['strprivileges'] | ||
| 400 | ) . \PHP_EOL; | ||
| 401 | echo '<td class="data1">' . \PHP_EOL; | ||
| 402 | |||
| 403 |         foreach ($data->privlist[$_REQUEST['subject']] as $v) { | ||
| 404 | $v = \htmlspecialchars($v); | ||
| 405 | echo \sprintf( | ||
| 406 | '<input type="checkbox" id="privilege[%s]" name="privilege[%s]"', | ||
| 407 | $v, | ||
| 408 | $v | ||
| 409 | ), | ||
| 410 | isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', \sprintf( | ||
| 411 | ' /><label for="privilege[%s]">%s</label><br />', | ||
| 412 | $v, | ||
| 413 | $v | ||
| 414 | ) . \PHP_EOL; | ||
| 415 | } | ||
| 416 | echo '</td></tr>' . \PHP_EOL; | ||
| 417 | // Grant option | ||
| 418 |         if ($data->hasGrantOption()) { | ||
| 419 | echo \sprintf( | ||
| 420 | '<tr><th class="data left">%s</th>', | ||
| 421 | $this->lang['stroptions'] | ||
| 422 | ) . \PHP_EOL; | ||
| 423 | echo '<td class="data1">' . \PHP_EOL; | ||
| 424 | |||
| 425 |             if ('grant' === $mode) { | ||
| 426 | echo '<input type="checkbox" id="grantoption" name="grantoption"', | ||
| 427 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION</label>' . \PHP_EOL; | ||
| 428 |             } elseif ('revoke' === $mode) { | ||
| 429 | echo '<input type="checkbox" id="grantoption" name="grantoption"', | ||
| 430 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION FOR</label><br />' . \PHP_EOL; | ||
| 431 | echo '<input type="checkbox" id="cascade" name="cascade"', | ||
| 432 | isset($_REQUEST['cascade']) ? ' checked="checked"' : '', ' /><label for="cascade">CASCADE</label><br />' . \PHP_EOL; | ||
| 433 | } | ||
| 434 | echo '</td></tr>' . \PHP_EOL; | ||
| 435 | } | ||
| 436 | echo '</table>' . \PHP_EOL; | ||
| 437 | |||
| 438 | echo '<p><input type="hidden" name="action" value="save" />' . \PHP_EOL; | ||
| 439 | echo '<input type="hidden" name="mode" value="', \htmlspecialchars($mode), '" />' . \PHP_EOL; | ||
| 440 | echo '<input type="hidden" name="subject" value="', \htmlspecialchars($_REQUEST['subject']), '" />' . \PHP_EOL; | ||
| 441 | |||
| 442 |         if (isset($_REQUEST[$_REQUEST['subject'] . '_oid'])) { | ||
| 443 | echo '<input type="hidden" name="', \htmlspecialchars($_REQUEST['subject'] . '_oid'), | ||
| 444 | '" value="', \htmlspecialchars($_REQUEST[$_REQUEST['subject'] . '_oid']), '" />' . \PHP_EOL; | ||
| 445 | } | ||
| 446 | |||
| 447 | echo '<input type="hidden" name="', \htmlspecialchars($_REQUEST['subject']), | ||
| 448 | '" value="', \htmlspecialchars($_REQUEST[$_REQUEST['subject']]), '" />' . \PHP_EOL; | ||
| 449 | |||
| 450 |         if ('column' === $_REQUEST['subject']) { | ||
| 451 | echo '<input type="hidden" name="table" value="', | ||
| 452 | \htmlspecialchars($_REQUEST['table']), '" />' . \PHP_EOL; | ||
| 453 | } | ||
| 454 | |||
| 455 | echo $this->view->form; | ||
| 456 | echo \sprintf( | ||
| 457 | '<input type="submit" name="%s" value="%s" />%s', | ||
| 458 | $mode, | ||
| 459 | $this->lang['str' . $mode], | ||
| 460 | \PHP_EOL | ||
| 461 | ); | ||
| 462 | |||
| 463 | echo \sprintf( | ||
| 464 | '<input type="submit" name="cancel" value="%s" /></p>', | ||
| 465 | $this->lang['strcancel'] | ||
| 466 | ); | ||
| 467 | echo '</form>' . \PHP_EOL; | ||
| 468 | } | ||
| 520 |