Conditions | 25 |
Paths | > 20000 |
Total Lines | 121 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
52 | public function index(bool $executeActions = true): bool |
||
53 | { |
||
54 | global $conf; |
||
55 | global $db; |
||
56 | global $user; |
||
57 | global $hookmanager; |
||
58 | global $user; |
||
59 | global $menumanager; |
||
60 | global $langs; |
||
61 | |||
62 | |||
63 | // Load translation files required by the page |
||
64 | $langs->loadLangs(["agenda", "other"]); |
||
65 | |||
66 | // Get parameters |
||
67 | $id = GETPOSTINT('id'); |
||
68 | $ref = GETPOST('ref', 'alpha'); |
||
69 | $action = GETPOST('action', 'aZ09'); |
||
70 | $cancel = GETPOST('cancel', 'aZ09'); |
||
71 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)) . basename(__FILE__, '.php')); // To manage different context of search |
||
72 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
73 | |||
74 | if (GETPOST('actioncode', 'array')) { |
||
75 | $actioncode = GETPOST('actioncode', 'array', 3); |
||
76 | if (!count($actioncode)) { |
||
77 | $actioncode = '0'; |
||
78 | } |
||
79 | } else { |
||
80 | $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT')); |
||
81 | } |
||
82 | $search_rowid = GETPOST('search_rowid'); |
||
83 | $search_agenda_label = GETPOST('search_agenda_label'); |
||
84 | |||
85 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
86 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
87 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
88 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
89 | if (empty($page) || $page == -1) { |
||
90 | $page = 0; |
||
91 | } // If $page is not defined, or '' or -1 |
||
92 | $offset = $limit * $page; |
||
93 | $pageprev = $page - 1; |
||
94 | $pagenext = $page + 1; |
||
95 | if (!$sortfield) { |
||
96 | $sortfield = 'a.datep,a.id'; |
||
97 | } |
||
98 | if (!$sortorder) { |
||
99 | $sortorder = 'DESC,DESC'; |
||
100 | } |
||
101 | |||
102 | // Initialize technical objects |
||
103 | $object = new Calendar($db); |
||
104 | $extrafields = new ExtraFields($db); |
||
105 | $diroutputmassaction = $conf->bookcal->dir_output . '/temp/massgeneration/' . $user->id; |
||
106 | $hookmanager->initHooks(['calendaragenda', 'globalcard']); // Note that conf->hooks_modules contains array |
||
107 | // Fetch optionals attributes and labels |
||
108 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
109 | |||
110 | // Load object |
||
111 | 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 |
||
112 | if ($id > 0 || !empty($ref)) { |
||
113 | $upload_dir = $conf->bookcal->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity] . "/" . $object->id; |
||
114 | } |
||
115 | |||
116 | // There is several ways to check permission. |
||
117 | // Set $enablepermissioncheck to 1 to enable a minimum low level of checks |
||
118 | $enablepermissioncheck = 0; |
||
119 | if ($enablepermissioncheck) { |
||
120 | $permissiontoread = $user->hasRight('bookcal', 'calendar', 'read'); |
||
121 | $permissiontoadd = $user->hasRight('bookcal', 'calendar', 'write'); |
||
122 | } else { |
||
123 | $permissiontoread = 1; |
||
124 | $permissiontoadd = 1; |
||
125 | } |
||
126 | |||
127 | // Security check (enable the most restrictive one) |
||
128 | //if ($user->socid > 0) accessforbidden(); |
||
129 | //if ($user->socid > 0) $socid = $user->socid; |
||
130 | //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
131 | //restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft); |
||
132 | if (!isModEnabled("bookcal")) { |
||
133 | accessforbidden(); |
||
134 | } |
||
135 | if (!$permissiontoread) { |
||
136 | accessforbidden(); |
||
137 | } |
||
138 | |||
139 | |||
140 | /* |
||
141 | * Actions |
||
142 | */ |
||
143 | |||
144 | $parameters = ['id' => $id]; |
||
145 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
146 | if ($reshook < 0) { |
||
147 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
148 | } |
||
149 | |||
150 | if (empty($reshook)) { |
||
151 | // Cancel |
||
152 | if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { |
||
153 | header("Location: " . $backtopage); |
||
154 | exit; |
||
|
|||
155 | } |
||
156 | |||
157 | // Purge search criteria |
||
158 | 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 |
||
159 | $actioncode = ''; |
||
160 | $search_agenda_label = ''; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | |||
165 | /* |
||
166 | * View |
||
167 | */ |
||
168 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/calendar_agenda.php'); |
||
169 | |||
170 | $db->close(); |
||
171 | |||
172 | return true; |
||
173 | } |
||
175 |
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: