Conditions | 17 |
Paths | 128 |
Total Lines | 98 |
Code Lines | 66 |
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 |
||
298 | public function formAlter($mode, $msg = ''): void |
||
299 | { |
||
300 | $data = $this->misc->getDatabaseAccessor(); |
||
301 | |||
302 | $this->coalesceArr($_REQUEST, 'username', []); |
||
303 | |||
304 | $this->coalesceArr($_REQUEST, 'groupname', []); |
||
305 | |||
306 | $this->coalesceArr($_REQUEST, 'privilege', []); |
||
307 | |||
308 | // Get users from the database |
||
309 | $users = $data->getUsers(); |
||
310 | // Get groups from the database |
||
311 | $groups = $data->getGroups(); |
||
312 | |||
313 | $this->printTrail($_REQUEST['subject']); |
||
314 | |||
315 | $this->printTitle($this->lang['str' . $mode], 'pg.privilege.' . $mode); |
||
316 | |||
317 | $this->printMsg($msg); |
||
318 | |||
319 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/privileges" method="post">' . \PHP_EOL; |
||
320 | echo '<table>' . \PHP_EOL; |
||
321 | echo "<tr><th class=\"data left\">{$this->lang['strusers']}</th>" . \PHP_EOL; |
||
322 | echo '<td class="data1"><select name="username[]" multiple="multiple" size="', \min(6, $users->recordCount()), '">' . \PHP_EOL; |
||
323 | |||
324 | while (!$users->EOF) { |
||
325 | $uname = \htmlspecialchars($users->fields['usename']); |
||
326 | echo "<option value=\"{$uname}\"", |
||
327 | \in_array($users->fields['usename'], $_REQUEST['username'], true) ? ' selected="selected"' : '', ">{$uname}</option>" . \PHP_EOL; |
||
328 | $users->moveNext(); |
||
329 | } |
||
330 | echo '</select></td></tr>' . \PHP_EOL; |
||
331 | echo "<tr><th class=\"data left\">{$this->lang['strgroups']}</th>" . \PHP_EOL; |
||
332 | echo '<td class="data1">' . \PHP_EOL; |
||
333 | echo '<input type="checkbox" id="public" name="public"', (isset($_REQUEST['public']) ? ' checked="checked"' : ''), ' /><label for="public">PUBLIC</label>' . \PHP_EOL; |
||
334 | // Only show groups if there are groups! |
||
335 | if (0 < $groups->recordCount()) { |
||
336 | echo '<br /><select name="groupname[]" multiple="multiple" size="', \min(6, $groups->recordCount()), '">' . \PHP_EOL; |
||
337 | |||
338 | while (!$groups->EOF) { |
||
339 | $gname = \htmlspecialchars($groups->fields['groname']); |
||
340 | echo "<option value=\"{$gname}\"", |
||
341 | \in_array($groups->fields['groname'], $_REQUEST['groupname'], true) ? ' selected="selected"' : '', ">{$gname}</option>" . \PHP_EOL; |
||
342 | $groups->moveNext(); |
||
343 | } |
||
344 | echo '</select>' . \PHP_EOL; |
||
345 | } |
||
346 | echo '</td></tr>' . \PHP_EOL; |
||
347 | echo "<tr><th class=\"data left required\">{$this->lang['strprivileges']}</th>" . \PHP_EOL; |
||
348 | echo '<td class="data1">' . \PHP_EOL; |
||
349 | |||
350 | foreach ($data->privlist[$_REQUEST['subject']] as $v) { |
||
351 | $v = \htmlspecialchars($v); |
||
352 | echo "<input type=\"checkbox\" id=\"privilege[{$v}]\" name=\"privilege[{$v}]\"", |
||
353 | isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', " /><label for=\"privilege[{$v}]\">{$v}</label><br />" . \PHP_EOL; |
||
354 | } |
||
355 | echo '</td></tr>' . \PHP_EOL; |
||
356 | // Grant option |
||
357 | if ($data->hasGrantOption()) { |
||
358 | echo "<tr><th class=\"data left\">{$this->lang['stroptions']}</th>" . \PHP_EOL; |
||
359 | echo '<td class="data1">' . \PHP_EOL; |
||
360 | |||
361 | if ('grant' === $mode) { |
||
362 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
363 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION</label>' . \PHP_EOL; |
||
364 | } elseif ('revoke' === $mode) { |
||
365 | echo '<input type="checkbox" id="grantoption" name="grantoption"', |
||
366 | isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', ' /><label for="grantoption">GRANT OPTION FOR</label><br />' . \PHP_EOL; |
||
367 | echo '<input type="checkbox" id="cascade" name="cascade"', |
||
368 | isset($_REQUEST['cascade']) ? ' checked="checked"' : '', ' /><label for="cascade">CASCADE</label><br />' . \PHP_EOL; |
||
369 | } |
||
370 | echo '</td></tr>' . \PHP_EOL; |
||
371 | } |
||
372 | echo '</table>' . \PHP_EOL; |
||
373 | |||
374 | echo '<p><input type="hidden" name="action" value="save" />' . \PHP_EOL; |
||
375 | echo '<input type="hidden" name="mode" value="', \htmlspecialchars($mode), '" />' . \PHP_EOL; |
||
376 | echo '<input type="hidden" name="subject" value="', \htmlspecialchars($_REQUEST['subject']), '" />' . \PHP_EOL; |
||
377 | |||
378 | if (isset($_REQUEST[$_REQUEST['subject'] . '_oid'])) { |
||
379 | echo '<input type="hidden" name="', \htmlspecialchars($_REQUEST['subject'] . '_oid'), |
||
380 | '" value="', \htmlspecialchars($_REQUEST[$_REQUEST['subject'] . '_oid']), '" />' . \PHP_EOL; |
||
381 | } |
||
382 | |||
383 | echo '<input type="hidden" name="', \htmlspecialchars($_REQUEST['subject']), |
||
384 | '" value="', \htmlspecialchars($_REQUEST[$_REQUEST['subject']]), '" />' . \PHP_EOL; |
||
385 | |||
386 | if ('column' === $_REQUEST['subject']) { |
||
387 | echo '<input type="hidden" name="table" value="', |
||
388 | \htmlspecialchars($_REQUEST['table']), '" />' . \PHP_EOL; |
||
389 | } |
||
390 | |||
391 | echo $this->view->form; |
||
392 | echo \sprintf('<input type="submit" name="%s" value="%s" />%s', $mode, $this->lang['str' . $mode], \PHP_EOL); |
||
393 | |||
394 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>"; |
||
395 | echo '</form>' . \PHP_EOL; |
||
396 | } |
||
448 |