| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 127 |
| Code Lines | 76 |
| 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 |
||
| 50 | public function index(bool $executeActions = true): bool |
||
| 51 | { |
||
| 52 | global $conf; |
||
| 53 | global $db; |
||
| 54 | global $user; |
||
| 55 | global $hookmanager; |
||
| 56 | global $user; |
||
| 57 | global $menumanager; |
||
| 58 | global $langs; |
||
| 59 | |||
| 60 | |||
| 61 | // Load translation files required by the page |
||
| 62 | $langs->loadLangs(['bookmarks', 'admin']); |
||
| 63 | |||
| 64 | // Get Parameters |
||
| 65 | $action = GETPOST('action', 'aZ09'); |
||
| 66 | $massaction = GETPOST('massaction', 'alpha'); |
||
| 67 | $show_files = GETPOSTINT('show_files'); |
||
| 68 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 69 | $cancel = GETPOST('cancel', 'alpha'); |
||
| 70 | $toselect = GETPOST('toselect', 'array'); |
||
| 71 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search |
||
| 72 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 73 | $optioncss = GETPOST('optioncss', 'alpha'); |
||
| 74 | $mode = GETPOST('mode', 'aZ'); |
||
| 75 | |||
| 76 | $id = GETPOSTINT("id"); |
||
| 77 | $search_title = GETPOST('search_title', 'alpha'); |
||
| 78 | |||
| 79 | // Load variable for pagination |
||
| 80 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
| 81 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 82 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 83 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 84 | if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { |
||
| 85 | // If $page is not defined, or '' or -1 or if we click on clear filters |
||
| 86 | $page = 0; |
||
| 87 | } |
||
| 88 | $offset = $limit * $page; |
||
| 89 | $pageprev = $page - 1; |
||
| 90 | $pagenext = $page + 1; |
||
| 91 | if (!$sortfield) { |
||
| 92 | $sortfield = 'b.position'; |
||
| 93 | } |
||
| 94 | if (!$sortorder) { |
||
| 95 | $sortorder = 'ASC'; |
||
| 96 | } |
||
| 97 | |||
| 98 | // Initialize Objects |
||
| 99 | $object = new Bookmark($db); |
||
| 100 | $extrafields = new ExtraFields($db); |
||
| 101 | $arrayfields = []; |
||
| 102 | $hookmanager->initHooks(['bookmarklist']); // Note that conf->hooks_modules contains array |
||
| 103 | |||
| 104 | if ($id > 0) { |
||
| 105 | $object->fetch($id); |
||
| 106 | } |
||
| 107 | |||
| 108 | $object->fields = dol_sort_array($object->fields, 'position'); |
||
| 109 | $arrayfields = dol_sort_array($arrayfields, 'position'); |
||
| 110 | |||
| 111 | // Security check |
||
| 112 | restrictedArea($user, 'bookmark', $object); |
||
| 113 | |||
| 114 | // Permissions |
||
| 115 | $permissiontoread = $user->hasRight('bookmark', 'lire'); |
||
| 116 | $permissiontoadd = $user->hasRight('bookmark', 'creer'); |
||
| 117 | $permissiontodelete = ($user->hasRight('bookmark', 'supprimer') || ($permissiontoadd && $object->fk_user == $user->id)); |
||
| 118 | |||
| 119 | |||
| 120 | /* |
||
| 121 | * Actions |
||
| 122 | */ |
||
| 123 | |||
| 124 | if (GETPOST('cancel', 'alpha')) { |
||
| 125 | $action = 'list'; |
||
| 126 | $massaction = ''; |
||
| 127 | } |
||
| 128 | if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { |
||
| 129 | $massaction = ''; |
||
| 130 | } |
||
| 131 | |||
| 132 | $parameters = []; |
||
| 133 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 134 | if ($reshook < 0) { |
||
| 135 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 136 | } |
||
| 137 | |||
| 138 | if (empty($reshook)) { |
||
| 139 | // Selection of new fields |
||
| 140 | include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php'; |
||
| 141 | |||
| 142 | if ( |
||
| 143 | GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') |
||
| 144 | || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha') |
||
| 145 | ) { |
||
| 146 | $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation |
||
| 147 | } |
||
| 148 | |||
| 149 | // Mass actions |
||
| 150 | $objectclass = 'Bookmark'; |
||
| 151 | $objectlabel = 'Bookmark'; |
||
| 152 | $uploaddir = $conf->bookmark->dir_output; |
||
| 153 | include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php'; |
||
| 154 | |||
| 155 | if ($action == 'delete' && $permissiontodelete) { |
||
| 156 | $object->fetch($id); |
||
| 157 | $res = $object->delete($user); |
||
| 158 | if ($res > 0) { |
||
| 159 | header("Location: " . $_SERVER['PHP_SELF']); |
||
| 160 | exit; |
||
|
|
|||
| 161 | } else { |
||
| 162 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 163 | $action = ''; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | |||
| 169 | /* |
||
| 170 | * View |
||
| 171 | */ |
||
| 172 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookMarks/Views/list.php'); |
||
| 173 | |||
| 174 | $db->close(); |
||
| 175 | |||
| 176 | return true; |
||
| 177 | } |
||
| 179 |
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: