| Conditions | 12 |
| Paths | 384 |
| Total Lines | 84 |
| Code Lines | 41 |
| 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 |
||
| 51 | public function index(bool $executeActions = true): bool |
||
| 52 | { |
||
| 53 | global $conf; |
||
| 54 | global $db; |
||
| 55 | global $user; |
||
| 56 | global $hookmanager; |
||
| 57 | global $user; |
||
| 58 | global $menumanager; |
||
| 59 | global $langs; |
||
| 60 | global $mysoc; |
||
| 61 | |||
| 62 | // Load translation files required by the page |
||
| 63 | $langs->loadLangs(["mrp", "companies", "other", "mails"]); |
||
| 64 | |||
| 65 | // Get parameters |
||
| 66 | $action = GETPOST('action', 'aZ09'); |
||
| 67 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 68 | $id = (GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id')); |
||
| 69 | $ref = GETPOST('ref', 'alpha'); |
||
| 70 | |||
| 71 | // Security check - Protection if external user |
||
| 72 | // if ($user->socid > 0) accessforbidden(); |
||
| 73 | // if ($user->socid > 0) $socid = $user->socid; |
||
| 74 | // $result = restrictedArea($user, 'bom', $id); |
||
| 75 | |||
| 76 | // Load variables for pagination |
||
| 77 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
| 78 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 79 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 80 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 81 | if (empty($page) || $page == -1) { |
||
| 82 | $page = 0; |
||
| 83 | } // If $page is not defined, or '' or -1 |
||
| 84 | $offset = $limit * $page; |
||
| 85 | $pageprev = $page - 1; |
||
| 86 | $pagenext = $page + 1; |
||
| 87 | if (!$sortorder) { |
||
| 88 | $sortorder = "ASC"; |
||
| 89 | } |
||
| 90 | if (!$sortfield) { |
||
| 91 | $sortfield = "name"; |
||
| 92 | } |
||
| 93 | //if (! $sortfield) $sortfield="position_name"; |
||
| 94 | |||
| 95 | // Initialize technical objects |
||
| 96 | $object = new Bom($db); |
||
| 97 | $extrafields = new ExtraFields($db); |
||
| 98 | $diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/' . $user->id; |
||
| 99 | $hookmanager->initHooks(['bomdocument', 'globalcard']); // Note that conf->hooks_modules contains array |
||
| 100 | // Fetch optionals attributes and labels |
||
| 101 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 102 | |||
| 103 | // Load object |
||
| 104 | 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 |
||
| 105 | |||
| 106 | if ($id > 0 || !empty($ref)) { |
||
| 107 | $upload_dir = $conf->bom->multidir_output[$object->entity ? $object->entity : 1] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 108 | } |
||
| 109 | |||
| 110 | // Security check - Protection if external user |
||
| 111 | //if ($user->socid > 0) accessforbidden(); |
||
| 112 | //if ($user->socid > 0) $socid = $user->socid; |
||
| 113 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
| 114 | restrictedArea($user, 'bom', $object->id, $object->table_element, '', '', 'rowid', $isdraft); |
||
| 115 | |||
| 116 | $permissiontoadd = $user->hasRight('bom', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php |
||
| 117 | |||
| 118 | |||
| 119 | /* |
||
| 120 | * Actions |
||
| 121 | */ |
||
| 122 | |||
| 123 | include DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; |
||
| 124 | |||
| 125 | |||
| 126 | /* |
||
| 127 | * View |
||
| 128 | */ |
||
| 129 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Bom/Views/bom_document.php'); |
||
| 130 | |||
| 131 | |||
| 132 | $db->close(); |
||
| 133 | |||
| 134 | return true; |
||
| 135 | } |
||
| 137 |