| Conditions | 36 |
| Paths | 480 |
| Total Lines | 180 |
| Code Lines | 117 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 33 |
| CRAP Score | 505.7573 |
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 |
||
| 200 | 1 | protected function createSugarIcal(&$user_bean,&$start_date_time,&$end_date_time, $dtstamp) |
|
| 201 | { |
||
| 202 | 1 | $ical_array = array(); |
|
| 203 | 1 | global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate; |
|
| 204 | |||
| 205 | 1 | $hide_calls = false; |
|
| 206 | 1 | if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") |
|
| 207 | { |
||
| 208 | $hide_calls = true; |
||
| 209 | } |
||
| 210 | |||
| 211 | 1 | $taskAsVTODO = true; |
|
| 212 | 1 | if (!empty($_REQUEST['show_tasks_as_events']) && ($_REQUEST['show_tasks_as_events'] == "1" || $_REQUEST['show_tasks_as_events'] == "true")) |
|
| 213 | { |
||
| 214 | $taskAsVTODO = false; |
||
| 215 | } |
||
| 216 | |||
| 217 | 1 | $acts_arr = CalendarActivity::get_activities($user_bean->id, |
|
| 218 | 1 | !$taskAsVTODO, |
|
| 219 | $start_date_time, |
||
|
|
|||
| 220 | $end_date_time, |
||
| 221 | 1 | 'month', |
|
| 222 | 1 | !$hide_calls); |
|
| 223 | |||
| 224 | |||
| 225 | // loop thru each activity, get start/end time in UTC, and return iCal strings |
||
| 226 | 1 | foreach($acts_arr as $act) |
|
| 227 | { |
||
| 228 | |||
| 229 | $event = $act->sugar_bean; |
||
| 230 | if (!$hide_calls || ($hide_calls && $event->object_name != "Call")) |
||
| 231 | { |
||
| 232 | $ical_array[] = array("BEGIN", "VEVENT"); |
||
| 233 | $ical_array[] = array("SUMMARY", $event->name); |
||
| 234 | $ical_array[] = array( |
||
| 235 | "DTSTART;TZID=" . $user_bean->getPreference('timezone'), |
||
| 236 | str_replace( |
||
| 237 | "Z", |
||
| 238 | "", |
||
| 239 | $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT) |
||
| 240 | ) |
||
| 241 | ); |
||
| 242 | $ical_array[] = array( |
||
| 243 | "DTEND;TZID=" . $user_bean->getPreference('timezone'), |
||
| 244 | str_replace( |
||
| 245 | "Z", |
||
| 246 | "", |
||
| 247 | $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT) |
||
| 248 | ) |
||
| 249 | ); |
||
| 250 | $ical_array[] = array("DTSTAMP", $dtstamp); |
||
| 251 | $ical_array[] = array("DESCRIPTION", $event->description); |
||
| 252 | $ical_array[] = array( |
||
| 253 | "URL;VALUE=URI", |
||
| 254 | $sugar_config['site_url']."/index.php?module=". |
||
| 255 | $event->module_dir."&action=DetailView&record=". $event->id |
||
| 256 | ); |
||
| 257 | $ical_array[] = array("UID", $event->id); |
||
| 258 | if ($event->object_name == "Meeting") |
||
| 259 | { |
||
| 260 | $ical_array[] = array("LOCATION", $event->location); |
||
| 261 | $eventUsers = $event->get_meeting_users(); |
||
| 262 | $query = "SELECT contact_id as id from meetings_contacts where meeting_id='$event->id' AND deleted=0"; |
||
| 263 | $eventContacts = $event->build_related_list($query, new Contact()); |
||
| 264 | $eventAttendees = array_merge($eventUsers, $eventContacts); |
||
| 265 | if (is_array($eventAttendees)) |
||
| 266 | { |
||
| 267 | foreach($eventAttendees as $attendee) |
||
| 268 | { |
||
| 269 | if ($attendee->id != $user_bean->id) |
||
| 270 | { |
||
| 271 | // Define the participant status |
||
| 272 | $participant_status = ''; |
||
| 273 | if (!empty($attendee->accept_status)) { |
||
| 274 | switch ($attendee->accept_status) { |
||
| 275 | case 'accept': |
||
| 276 | $participant_status = ';PARTSTAT=ACCEPTED'; |
||
| 277 | break; |
||
| 278 | case 'decline': |
||
| 279 | $participant_status = ';PARTSTAT=DECLINED'; |
||
| 280 | break; |
||
| 281 | case 'tentative': |
||
| 282 | $participant_status = ';PARTSTAT=TENTATIVE'; |
||
| 283 | break; |
||
| 284 | } |
||
| 285 | } |
||
| 286 | $ical_array[] = array( |
||
| 287 | 'ATTENDEE'.$participant_status.';CN="'.$attendee->get_summary_text().'"', |
||
| 288 | 'mailto:'.(!empty($attendee->email1) ? $attendee->email1:'[email protected]') |
||
| 289 | ); |
||
| 290 | } |
||
| 291 | } |
||
| 292 | } |
||
| 293 | } |
||
| 294 | if ($event->object_name == "Call") |
||
| 295 | { |
||
| 296 | $eventUsers = $event->get_call_users(); |
||
| 297 | $eventContacts = $event->get_contacts(); |
||
| 298 | $eventAttendees = array_merge($eventUsers, $eventContacts); |
||
| 299 | if (is_array($eventAttendees)) |
||
| 300 | { |
||
| 301 | foreach($eventAttendees as $attendee) |
||
| 302 | { |
||
| 303 | if ($attendee->id != $user_bean->id) |
||
| 304 | { |
||
| 305 | // Define the participant status |
||
| 306 | $participant_status = ''; |
||
| 307 | if (!empty($attendee->accept_status)) { |
||
| 308 | switch ($attendee->accept_status) { |
||
| 309 | case 'accept': |
||
| 310 | $participant_status = ';PARTSTAT=ACCEPTED'; |
||
| 311 | break; |
||
| 312 | case 'decline': |
||
| 313 | $participant_status = ';PARTSTAT=DECLINED'; |
||
| 314 | break; |
||
| 315 | case 'tentative': |
||
| 316 | $participant_status = ';PARTSTAT=TENTATIVE'; |
||
| 317 | break; |
||
| 318 | } |
||
| 319 | } |
||
| 320 | $ical_array[] = array( |
||
| 321 | 'ATTENDEE'.$participant_status.';CN="'.$attendee->get_summary_text().'"', |
||
| 322 | 'mailto:'.(!empty($attendee->email1) ? $attendee->email1:'[email protected]') |
||
| 323 | ); |
||
| 324 | } |
||
| 325 | } |
||
| 326 | } |
||
| 327 | } |
||
| 328 | if (isset($event->reminder_time) && $event->reminder_time > 0 && $event->status != "Held") |
||
| 329 | { |
||
| 330 | $ical_array[] = array("BEGIN", "VALARM"); |
||
| 331 | $ical_array[] = array("TRIGGER", "-PT"); |
||
| 332 | $ical_array[] = array("ACTION", "DISPLAY"); |
||
| 333 | $ical_array[] = array("DESCRIPTION", $event->name); |
||
| 334 | $ical_array[] = array("END", "VALARM"); |
||
| 335 | } |
||
| 336 | $ical_array[] = array("END", "VEVENT"); |
||
| 337 | } |
||
| 338 | |||
| 339 | } |
||
| 340 | |||
| 341 | 1 | $str = vCal::create_ical_string_from_array($ical_array,true); |
|
| 342 | |||
| 343 | 1 | require_once('include/TimeDate.php'); |
|
| 344 | 1 | $timedate = new TimeDate(); |
|
| 345 | 1 | $today = gmdate("Y-m-d"); |
|
| 346 | 1 | $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false); |
|
| 347 | |||
| 348 | 1 | require_once('modules/ProjectTask/ProjectTask.php'); |
|
| 349 | 1 | $where = "project_task.assigned_user_id='{$user_bean->id}' ". |
|
| 350 | 1 | "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) ". |
|
| 351 | 1 | "AND (project_task.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('project_task', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")"; |
|
| 352 | 1 | $seedProjectTask = new ProjectTask(); |
|
| 353 | 1 | $projectTaskList = $seedProjectTask->get_full_list("", $where); |
|
| 354 | 1 | if (is_array($projectTaskList)) |
|
| 355 | { |
||
| 356 | foreach($projectTaskList as $projectTask) |
||
| 357 | { |
||
| 358 | $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp); |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | 1 | if ($taskAsVTODO) { |
|
| 363 | 1 | require_once('modules/Tasks/Task.php'); |
|
| 364 | 1 | $where = "tasks.assigned_user_id='{$user_bean->id}' ". |
|
| 365 | 1 | "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) ". |
|
| 366 | 1 | "AND (tasks.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('tasks', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")"; |
|
| 367 | 1 | $seedTask = new Task(); |
|
| 368 | 1 | $taskList = $seedTask->get_full_list("", $where); |
|
| 369 | 1 | if (is_array($taskList)) |
|
| 370 | { |
||
| 371 | foreach($taskList as $task) |
||
| 372 | { |
||
| 373 | $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp); |
||
| 374 | } |
||
| 375 | } |
||
| 376 | } |
||
| 377 | |||
| 378 | 1 | return $str; |
|
| 379 | } |
||
| 380 | |||
| 561 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.