| Conditions | 10 |
| Paths | 22 |
| Total Lines | 64 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 48 | public function blockedlog(bool $executeActions = true): bool |
||
| 49 | { |
||
| 50 | global $conf; |
||
| 51 | global $db; |
||
| 52 | global $user; |
||
| 53 | global $hookmanager; |
||
| 54 | global $user; |
||
| 55 | global $menumanager; |
||
| 56 | global $langs; |
||
| 57 | global $mysoc; |
||
| 58 | |||
| 59 | // Load translation files required by the page |
||
| 60 | $langs->loadLangs(['admin', 'blockedlog', 'other']); |
||
| 61 | |||
| 62 | // Access Control |
||
| 63 | if (!$user->admin || empty($conf->blockedlog->enabled)) { |
||
| 64 | accessforbidden(); |
||
| 65 | } |
||
| 66 | |||
| 67 | // Get Parameters |
||
| 68 | $action = GETPOST('action', 'aZ09'); |
||
| 69 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 70 | $withtab = GETPOSTINT('withtab'); |
||
| 71 | |||
| 72 | |||
| 73 | /* |
||
| 74 | * Actions |
||
| 75 | */ |
||
| 76 | |||
| 77 | $reg = []; |
||
| 78 | if (preg_match('/set_(.*)/', $action, $reg)) { |
||
| 79 | $code = $reg[1]; |
||
| 80 | $values = GETPOST($code); |
||
| 81 | if (is_array($values)) { |
||
| 82 | $values = implode(',', $values); |
||
| 83 | } |
||
| 84 | |||
| 85 | if (dolibarr_set_const($db, $code, $values, 'chaine', 0, '', $conf->entity) > 0) { |
||
| 86 | header("Location: " . $_SERVER['PHP_SELF'] . ($withtab ? '?withtab=' . $withtab : '')); |
||
| 87 | exit; |
||
|
|
|||
| 88 | } else { |
||
| 89 | dol_print_error($db); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | if (preg_match('/del_(.*)/', $action, $reg)) { |
||
| 94 | $code = $reg[1]; |
||
| 95 | if (dolibarr_del_const($db, $code, 0) > 0) { |
||
| 96 | header("Location: " . $_SERVER['PHP_SELF'] . ($withtab ? '?withtab=' . $withtab : '')); |
||
| 97 | exit; |
||
| 98 | } else { |
||
| 99 | dol_print_error($db); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | |||
| 104 | /* |
||
| 105 | * View |
||
| 106 | */ |
||
| 107 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BlockedLog/Views/admin_blocked_log.php'); |
||
| 108 | |||
| 109 | $db->close(); |
||
| 110 | |||
| 111 | return true; |
||
| 112 | } |
||
| 114 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: