| Conditions | 7 |
| Paths | 24 |
| Total Lines | 76 |
| Code Lines | 34 |
| 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 index(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 | |||
| 60 | // Load translation files required by the page |
||
| 61 | $langs->loadLangs(["mrp", "companies"]); |
||
| 62 | |||
| 63 | // Get parameters |
||
| 64 | $id = GETPOSTINT('id'); |
||
| 65 | $ref = GETPOST('ref', 'alpha'); |
||
| 66 | $action = GETPOST('action', 'aZ09'); |
||
| 67 | $cancel = GETPOST('cancel', 'aZ09'); |
||
| 68 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 69 | |||
| 70 | // Initialize technical objects |
||
| 71 | $object = new Bom($db); |
||
| 72 | $extrafields = new ExtraFields($db); |
||
| 73 | |||
| 74 | // Initialize technical objects for hooks |
||
| 75 | $hookmanager->initHooks(['bomnote', 'globalcard']); // Note that conf->hooks_modules contains array |
||
| 76 | |||
| 77 | // Massactions |
||
| 78 | $diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/' . $user->id; |
||
| 79 | |||
| 80 | // Fetch optionals attributes and labels |
||
| 81 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 82 | |||
| 83 | // Security check - Protection if external user |
||
| 84 | //if ($user->socid > 0) accessforbidden(); |
||
| 85 | //if ($user->socid > 0) $socid = $user->socid; |
||
| 86 | //$result = restrictedArea($user, 'bom', $id); |
||
| 87 | |||
| 88 | // Load object |
||
| 89 | 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 |
||
| 90 | if ($id > 0 || !empty($ref)) { |
||
| 91 | $upload_dir = (!empty($conf->bom->multidir_output[$object->entity]) ? $conf->bom->multidir_output[$object->entity] : $conf->bom->dir_output) . "/" . $object->id; |
||
| 92 | } |
||
| 93 | |||
| 94 | $permissionnote = $user->hasRight('bom', 'write'); // Used by the include of actions_setnotes.inc.php |
||
| 95 | |||
| 96 | // Security check - Protection if external user |
||
| 97 | //if ($user->socid > 0) accessforbidden(); |
||
| 98 | //if ($user->socid > 0) $socid = $user->socid; |
||
| 99 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
| 100 | restrictedArea($user, 'bom', $object->id, $object->table_element, '', '', 'rowid', $isdraft); |
||
| 101 | |||
| 102 | |||
| 103 | /* |
||
| 104 | * Actions |
||
| 105 | */ |
||
| 106 | |||
| 107 | $parameters = []; |
||
| 108 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 109 | if ($reshook < 0) { |
||
| 110 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 111 | } |
||
| 112 | if (empty($reshook)) { |
||
| 113 | include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once |
||
| 114 | } |
||
| 115 | |||
| 116 | |||
| 117 | /* |
||
| 118 | * View |
||
| 119 | */ |
||
| 120 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Bom/Views/bom_note.php'); |
||
| 121 | |||
| 122 | $db->close(); |
||
| 123 | return true; |
||
| 124 | } |
||
| 126 |