| Conditions | 22 |
| Paths | 9216 |
| Total Lines | 107 |
| Code Lines | 60 |
| 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 |
||
| 49 | public function index(bool $executeActions = true): bool |
||
| 50 | { |
||
| 51 | global $conf; |
||
| 52 | global $db; |
||
| 53 | global $user; |
||
| 54 | global $hookmanager; |
||
| 55 | global $user; |
||
| 56 | global $menumanager; |
||
| 57 | global $langs; |
||
| 58 | global $mysoc; |
||
| 59 | |||
| 60 | |||
| 61 | // Load translation files required by the page |
||
| 62 | $langs->loadLangs(['mrp', 'other']); |
||
| 63 | |||
| 64 | // Get parameters |
||
| 65 | $id = GETPOSTINT('id'); |
||
| 66 | $socid = GETPOSTINT('socid'); |
||
| 67 | $ref = GETPOST('ref', 'alpha'); |
||
| 68 | |||
| 69 | $action = GETPOST('action', 'aZ09'); |
||
| 70 | $cancel = GETPOST('cancel', 'aZ09'); |
||
| 71 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 72 | |||
| 73 | if (GETPOST('actioncode', 'array')) { |
||
| 74 | $actioncode = GETPOST('actioncode', 'array', 3); |
||
| 75 | if (!count($actioncode)) { |
||
| 76 | $actioncode = '0'; |
||
| 77 | } |
||
| 78 | } else { |
||
| 79 | $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT')); |
||
| 80 | } |
||
| 81 | |||
| 82 | $search_rowid = GETPOST('search_rowid'); |
||
| 83 | $search_agenda_label = GETPOST('search_agenda_label'); |
||
| 84 | |||
| 85 | // Load variables for pagination |
||
| 86 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
| 87 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 88 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 89 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 90 | if (empty($page) || $page == -1) { |
||
| 91 | $page = 0; |
||
| 92 | } // If $page is not defined, or '' or -1 |
||
| 93 | $offset = $limit * $page; |
||
| 94 | $pageprev = $page - 1; |
||
| 95 | $pagenext = $page + 1; |
||
| 96 | if (!$sortfield) { |
||
| 97 | $sortfield = 'a.datep,a.id'; |
||
| 98 | } |
||
| 99 | if (!$sortorder) { |
||
| 100 | $sortorder = 'DESC'; |
||
| 101 | } |
||
| 102 | |||
| 103 | // Initialize technical objects |
||
| 104 | $object = new Bom($db); |
||
| 105 | $extrafields = new ExtraFields($db); |
||
| 106 | $diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/' . $user->id; |
||
| 107 | $hookmanager->initHooks(['bomagenda', 'globalcard']); // Note that conf->hooks_modules contains array |
||
| 108 | |||
| 109 | // Fetch optionals attributes and labels |
||
| 110 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 111 | |||
| 112 | // Load object |
||
| 113 | include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals |
||
| 114 | if ($id > 0 || !empty($ref)) { |
||
| 115 | $upload_dir = (!empty($conf->bom->multidir_output[$object->entity]) ? $conf->bom->multidir_output[$object->entity] : $conf->bom->dir_output) . "/" . $object->id; |
||
| 116 | } |
||
| 117 | |||
| 118 | // Security check - Protection if external user |
||
| 119 | //if ($user->socid > 0) accessforbidden(); |
||
| 120 | //if ($user->socid > 0) $socid = $user->socid; |
||
| 121 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
| 122 | restrictedArea($user, 'bom', $object->id, $object->table_element, '', '', 'rowid', $isdraft); |
||
| 123 | |||
| 124 | /* |
||
| 125 | * Actions |
||
| 126 | */ |
||
| 127 | |||
| 128 | $parameters = ['id' => $socid]; |
||
| 129 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 130 | if ($reshook < 0) { |
||
| 131 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 132 | } |
||
| 133 | |||
| 134 | if (empty($reshook)) { |
||
| 135 | // Cancel |
||
| 136 | if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { |
||
| 137 | header("Location: " . $backtopage); |
||
| 138 | exit; |
||
|
|
|||
| 139 | } |
||
| 140 | |||
| 141 | // Purge search criteria |
||
| 142 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers |
||
| 143 | $actioncode = ''; |
||
| 144 | $search_agenda_label = ''; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | /* |
||
| 149 | * View |
||
| 150 | */ |
||
| 151 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Bom/Views/bom_agenda.php'); |
||
| 152 | |||
| 153 | $db->close(); |
||
| 154 | |||
| 155 | return true; |
||
| 156 | } |
||
| 158 |
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: