| Conditions | 15 |
| Paths | 2048 |
| Total Lines | 100 |
| Code Lines | 34 |
| 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 |
||
| 171 | function constructGanttLine($tarr, $task, $task_dependencies, $level = 0, $project_id = null) |
||
| 172 | { |
||
| 173 | global $langs; |
||
| 174 | global $dateformatinput2; |
||
| 175 | |||
| 176 | $start_date = $task["task_start_date"]; |
||
| 177 | $end_date = $task["task_end_date"]; |
||
| 178 | if (!$end_date) { |
||
| 179 | $end_date = $start_date; |
||
| 180 | } |
||
| 181 | $start_date = dol_print_date($start_date, $dateformatinput2); |
||
| 182 | $end_date = dol_print_date($end_date, $dateformatinput2); |
||
| 183 | // Resources |
||
| 184 | $resources = $task["task_resources"]; |
||
| 185 | |||
| 186 | // Define depend (ex: "", "4,13", ...) |
||
| 187 | $depend = ''; |
||
| 188 | $count = 0; |
||
| 189 | foreach ($task_dependencies as $value) { |
||
| 190 | // Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt)) |
||
| 191 | if ($value[0] == $task['task_id']) { |
||
| 192 | $depend .= ($count > 0 ? "," : "") . $value[1]; |
||
| 193 | $count++; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | // $depend .= "\""; |
||
| 197 | // Define parent |
||
| 198 | if ($project_id && $level < 0) { |
||
|
|
|||
| 199 | $parent = '-' . $project_id; |
||
| 200 | } else { |
||
| 201 | $parent = $task["task_parent_alternate_id"]; |
||
| 202 | //$parent = $task["task_parent"]; |
||
| 203 | } |
||
| 204 | // Define percent |
||
| 205 | $percent = empty($task['task_percent_complete']) ? 0 : $task['task_percent_complete']; |
||
| 206 | // Link (more information) |
||
| 207 | if ($task["task_id"] < 0) { |
||
| 208 | //$link=DOL_URL_ROOT.'/projet/tasks.php?withproject=1&id='.abs($task["task_id"]); |
||
| 209 | $link = ''; |
||
| 210 | } else { |
||
| 211 | $link = constant('BASE_URL') . '/projet/tasks/contact.php?withproject=1&id=' . $task["task_id"]; |
||
| 212 | } |
||
| 213 | |||
| 214 | // Name |
||
| 215 | //$name='<a href="'.DOL_URL_ROOT.'/projet/task/tasks.php?id='.$task['task_id'].'">'.$task['task_name'].'</a>'; |
||
| 216 | $name = $task['task_name']; |
||
| 217 | |||
| 218 | /*for($i=0; $i < $level; $i++) { |
||
| 219 | $name=' - '.$name; |
||
| 220 | }*/ |
||
| 221 | // Add line to gantt |
||
| 222 | /* |
||
| 223 | g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API','', '', 'ggroupblack','', 0, 'Brian', 0, 1,0,1,'','','Some Notes text',g)); |
||
| 224 | g.AddTaskItem(new JSGantt.TaskItem(11,'Chart Object', '2014-02-20','2014-02-20','gmilestone', '', 1, 'Shlomy',100,0,1,1,'','','',g)); |
||
| 225 | </pre> |
||
| 226 | <p>Method definition: |
||
| 227 | <strong>TaskItem(<em>pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt</em>)</strong></p> |
||
| 228 | <dl> |
||
| 229 | <dt>pID</dt><dd>(required) a unique numeric ID used to identify each row</dd> |
||
| 230 | <dt>pName</dt><dd>(required) the task Label</dd> |
||
| 231 | <dt>pStart</dt><dd>(required) the task start date, can enter empty date ('') for groups. You can also enter specific time (2014-02-20 12:00) for additional precision.</dd> |
||
| 232 | <dt>pEnd</dt><dd>(required) the task end date, can enter empty date ('') for groups</dd> |
||
| 233 | <dt>pClass</dt><dd>(required) the css class for this task</dd> |
||
| 234 | <dt>pLink</dt><dd>(optional) any http link to be displayed in tool tip as the "More information" link.</dd> |
||
| 235 | <dt>pMile</dt><dd>(optional) indicates whether this is a milestone task - Numeric; 1 = milestone, 0 = not milestone</dd> |
||
| 236 | <dt>press</dt><dd>(optional) resource name</dd> |
||
| 237 | <dt>pComp</dt><dd>(required) completion percent, numeric</dd> |
||
| 238 | <dt>pGroup</dt><dd>(optional) indicates whether this is a group task (parent) - Numeric; 0 = normal task, 1 = standard group task, 2 = combined group task<a href='#combinedtasks' class="footnote">*</a></dd> |
||
| 239 | <dt>pParent</dt><dd>(required) identifies a parent pID, this causes this task to be a child of identified task. Numeric, top level tasks should have pParent set to 0</dd> |
||
| 240 | <dt>pOpen</dt><dd>(required) indicates whether a standard group task is open when chart is first drawn. Value must be set for all items but is only used by standard group tasks. Numeric, 1 = open, 0 = closed</dd> |
||
| 241 | <dt>pDepend</dt><dd>(optional) comma separated list of id's this task is dependent on. A line will be drawn from each listed task to this item<br>Each id can optionally be followed by a dependency type suffix. Valid values are:<blockquote>'FS' - Finish to Start (default if suffix is omitted)<br>'SF' - Start to Finish<br>'SS' - Start to Start<br>'FF' - Finish to Finish</blockquote>If present the suffix must be added directly to the id e.g. '123SS'</dd> |
||
| 242 | <dt>pCaption</dt><dd>(optional) caption that will be added after task bar if CaptionType set to "Caption"</dd> |
||
| 243 | <dt>pNotes</dt><dd>(optional) Detailed task information that will be displayed in tool tip for this task</dd> |
||
| 244 | <dt>pGantt</dt><dd>(required) javascript JSGantt.GanttChart object from which to take settings. Defaults to "g" for backwards compatibility</dd> |
||
| 245 | */ |
||
| 246 | |||
| 247 | //$note=""; |
||
| 248 | |||
| 249 | $s = "\n// Add task level = " . $level . " id=" . $task["task_id"] . " parent_id=" . $task["task_parent"] . " aternate_id=" . $task["task_alternate_id"] . " parent_aternate_id=" . $task["task_parent_alternate_id"] . "\n"; |
||
| 250 | |||
| 251 | //$task["task_is_group"]=1; // When task_is_group is 1, content will be autocalculated from sum of all low tasks |
||
| 252 | |||
| 253 | // For JSGanttImproved |
||
| 254 | $css = $task['task_css']; |
||
| 255 | $line_is_auto_group = $task["task_is_group"]; |
||
| 256 | //$line_is_auto_group=0; |
||
| 257 | //if ($line_is_auto_group) $css = 'ggroupblack'; |
||
| 258 | //$dependency = ($depend?$depend:$parent."SS"); |
||
| 259 | $dependency = ''; |
||
| 260 | //$name = str_repeat("..", $level).$name; |
||
| 261 | |||
| 262 | $taskid = $task["task_alternate_id"]; |
||
| 263 | //$taskid = $task['task_id']; |
||
| 264 | |||
| 265 | $note = empty($task['note']) ? '' : $task['note']; |
||
| 266 | |||
| 267 | $note = dol_concatdesc($note, $langs->trans("Workload") . ' : ' . (empty($task['task_planned_workload']) ? '' : convertSecondToTime($task['task_planned_workload'], 'allhourmin'))); |
||
| 268 | |||
| 269 | $s .= "g.AddTaskItem(new JSGantt.TaskItem('" . $taskid . "', '" . dol_escape_js(trim($name)) . "', '" . $start_date . "', '" . $end_date . "', '" . $css . "', '" . $link . "', " . $task['task_milestone'] . ", '" . dol_escape_js($resources) . "', " . ($percent >= 0 ? $percent : 0) . ", " . $line_is_auto_group . ", '" . $parent . "', 1, '" . $dependency . "', '" . (empty($task["task_is_group"]) ? (($percent >= 0 && $percent != '') ? $percent . '%' : '') : '') . "', '" . dol_escape_js($note) . "', g));"; |
||
| 270 | echo $s; |
||
| 271 | } |
||
| 304 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: