| Conditions | 17 |
| Paths | 128 |
| Total Lines | 93 |
| Code Lines | 67 |
| 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 |
||
| 285 | public function formAlter($mode, $msg = '') |
||
| 286 | { |
||
| 287 | $data = $this->misc->getDatabaseAccessor(); |
||
| 288 | |||
| 289 | $this->coalesceArr($_REQUEST, 'username', []); |
||
| 290 | |||
| 291 | $this->coalesceArr($_REQUEST, 'groupname', []); |
||
| 292 | |||
| 293 | $this->coalesceArr($_REQUEST, 'privilege', []); |
||
| 294 | |||
| 295 | // Get users from the database |
||
| 296 | $users = $data->getUsers(); |
||
| 297 | // Get groups from the database |
||
| 298 | $groups = $data->getGroups(); |
||
| 299 | |||
| 300 | $this->printTrail($_REQUEST['subject']); |
||
| 301 | |||
| 302 | $this->printTitle($this->lang['str'.$mode], 'pg.privilege.'.$mode); |
||
| 303 | |||
| 304 | $this->printMsg($msg); |
||
| 305 | |||
| 306 | echo '<form action="'.\SUBFOLDER.'/src/views/privileges" method="post">'.PHP_EOL; |
||
| 307 | echo '<table>'.PHP_EOL; |
||
| 308 | echo "<tr><th class=\"data left\">{$this->lang['strusers']}</th>".PHP_EOL; |
||
| 309 | echo '<td class="data1"><select name="username[]" multiple="multiple" size="', min(6, $users->recordCount()), '">'.PHP_EOL; |
||
| 310 | while (!$users->EOF) { |
||
| 311 | $uname = htmlspecialchars($users->fields['usename']); |
||
| 312 | echo "<option value=\"{$uname}\"", |
||
| 313 | in_array($users->fields['usename'], $_REQUEST['username'], true) ? ' selected="selected"' : '', ">{$uname}</option>".PHP_EOL; |
||
| 314 | $users->moveNext(); |
||
| 315 | } |
||
| 316 | echo '</select></td></tr>'.PHP_EOL; |
||
| 317 | echo "<tr><th class=\"data left\">{$this->lang['strgroups']}</th>".PHP_EOL; |
||
| 318 | echo '<td class="data1">'.PHP_EOL; |
||
| 319 | echo '<input type="checkbox" id="public" name="public"', (isset($_REQUEST['public']) ? ' checked="checked"' : ''), ' /><label for="public">PUBLIC</label>'.PHP_EOL; |
||
| 320 | // Only show groups if there are groups! |
||
| 321 | if ($groups->recordCount() > 0) { |
||
| 322 | echo '<br /><select name="groupname[]" multiple="multiple" size="', min(6, $groups->recordCount()), '">'.PHP_EOL; |
||
| 323 | while (!$groups->EOF) { |
||
| 324 | $gname = htmlspecialchars($groups->fields['groname']); |
||
| 325 | echo "<option value=\"{$gname}\"", |
||
| 326 | in_array($groups->fields['groname'], $_REQUEST['groupname'], true) ? ' selected="selected"' : '', ">{$gname}</option>".PHP_EOL; |
||
| 327 | $groups->moveNext(); |
||
| 328 | } |
||
| 329 | echo '</select>'.PHP_EOL; |
||
| 330 | } |
||
| 331 | echo '</td></tr>'.PHP_EOL; |
||
| 332 | echo "<tr><th class=\"data left required\">{$this->lang['strprivileges']}</th>".PHP_EOL; |
||
| 333 | echo '<td class="data1">'.PHP_EOL; |
||
| 334 | foreach ($data->privlist[$_REQUEST['subject']] as $v) { |
||
| 335 | $v = htmlspecialchars($v); |
||
| 336 | echo "<input type=\"checkbox\" id=\"privilege[${v}]\" name=\"privilege[${v}]\"", |
||
| 337 | isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', " /><label for=\"privilege[${v}]\">{$v}</label><br />".PHP_EOL; |
||
| 338 | } |
||
| 339 | echo '</td></tr>'.PHP_EOL; |
||
| 340 | // Grant option |
||
| 341 | if ($data->hasGrantOption()) { |
||
| 342 | echo "<tr><th class=\"data left\">{$this->lang['stroptions']}</th>".PHP_EOL; |
||
| 343 | echo '<td class="data1">'.PHP_EOL; |
||
| 344 | if ('grant' == $mode) { |
||
| 345 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 346 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION</label>'.PHP_EOL; |
||
| 347 | } elseif ('revoke' == $mode) { |
||
| 348 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
| 349 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION FOR</label><br />'.PHP_EOL; |
||
| 350 | echo '<input type="checkbox" id="cascade" name="cascade"', |
||
| 351 | isset($_REQUEST['cascade']) ? ' checked="checked"' : '', ' /><label for="cascade">CASCADE</label><br />'.PHP_EOL; |
||
| 352 | } |
||
| 353 | echo '</td></tr>'.PHP_EOL; |
||
| 354 | } |
||
| 355 | echo '</table>'.PHP_EOL; |
||
| 356 | |||
| 357 | echo '<p><input type="hidden" name="action" value="save" />'.PHP_EOL; |
||
| 358 | echo '<input type="hidden" name="mode" value="', htmlspecialchars($mode), '" />'.PHP_EOL; |
||
| 359 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), '" />'.PHP_EOL; |
||
| 360 | if (isset($_REQUEST[$_REQUEST['subject'].'_oid'])) { |
||
| 361 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject'].'_oid'), |
||
| 362 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject'].'_oid']), '" />'.PHP_EOL; |
||
| 363 | } |
||
| 364 | |||
| 365 | echo '<input type="hidden" name="', htmlspecialchars($_REQUEST['subject']), |
||
| 366 | '" value="', htmlspecialchars($_REQUEST[$_REQUEST['subject']]), '" />'.PHP_EOL; |
||
| 367 | if ('column' == $_REQUEST['subject']) { |
||
| 368 | echo '<input type="hidden" name="table" value="', |
||
| 369 | htmlspecialchars($_REQUEST['table']), '" />'.PHP_EOL; |
||
| 370 | } |
||
| 371 | |||
| 372 | echo $this->misc->form; |
||
| 373 | echo sprintf('<input type="submit" name="%s" value="%s" />%s', $mode, $this->lang['str'.$mode], PHP_EOL); |
||
| 374 | |||
| 375 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>"; |
||
| 376 | echo '</form>'.PHP_EOL; |
||
| 377 | } |
||
| 378 | |||
| 429 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.