fossasia/engelsystem

View on GitHub
includes/controller/user_shifts_controller.php

Summary

Maintainability
F
3 wks
Test Coverage

Showing 20 of 20 total issues

Function view_user_shifts has a Cognitive Complexity of 324 (exceeds 5 allowed). Consider refactoring.
Open

function view_user_shifts() {
global $user, $privileges;
global $ical_shifts;
 
$ical_shifts = array();
Severity: Minor
Found in includes/controller/user_shifts_controller.php - About 6 days to fix

Function user_shifts has a Cognitive Complexity of 287 (exceeds 5 allowed). Consider refactoring.
Open

function user_shifts() {
global $user, $privileges;
$timezone_identifiers = DateTimeZone::listIdentifiers();
$timezone = $user['timezone'];
date_default_timezone_set ("$timezone_identifiers[$timezone]");
Severity: Minor
Found in includes/controller/user_shifts_controller.php - About 5 days to fix

Method user_shifts has 452 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function user_shifts() {
global $user, $privileges;
$timezone_identifiers = DateTimeZone::listIdentifiers();
$timezone = $user['timezone'];
date_default_timezone_set ("$timezone_identifiers[$timezone]");
Severity: Major
Found in includes/controller/user_shifts_controller.php - About 2 days to fix

    File user_shifts_controller.php has 874 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
     
    function shifts_title() {
    return _("Shifts");
    }
    Severity: Major
    Found in includes/controller/user_shifts_controller.php - About 2 days to fix

      Method view_user_shifts has 382 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function view_user_shifts() {
      global $user, $privileges;
      global $ical_shifts;
       
      $ical_shifts = array();
      Severity: Major
      Found in includes/controller/user_shifts_controller.php - About 1 day to fix

        Avoid deeply nested control flow statements.
        Open

        if (in_array('user_shifts_admin', $privileges))
        $shifts_row .= ' ' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs');
        Severity: Major
        Found in includes/controller/user_shifts_controller.php - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

          if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || $ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] || $ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end']) {
          $collides = true;
          break;
          }
          Severity: Major
          Found in includes/controller/user_shifts_controller.php - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

            if ($entry['freeloaded']) {
            $freeloader ++;
            $style = " text-decoration: line-through;";
            }
            Severity: Major
            Found in includes/controller/user_shifts_controller.php - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

              if ($angeltype['count'] - count($entries) - $freeloader > 0) {
              $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($entries)), $angeltype['count'] - count($entries));
              // is the shift still running or alternatively is the user shift admin?
              $user_may_join_shift = true;
               
               
              Severity: Major
              Found in includes/controller/user_shifts_controller.php - About 45 mins to fix

                Consider simplifying this complex logical expression.
                Open

                if ($ownshift['start'] >= $shift['start'] && $ownshift['start'] < $shift['end'] || $ownshift['end'] > $shift['start'] && $ownshift['end'] <= $shift['end'] || $ownshift['start'] < $shift['start'] && $ownshift['end'] > $shift['end']) {
                $collides = true;
                break;
                }
                Severity: Major
                Found in includes/controller/user_shifts_controller.php - About 40 mins to fix

                  Avoid too many return statements within this method.
                  Open

                  return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' &ndash; ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['Name'], $shift['name'], $angeltyppe_select, "", false, null, in_array('user_shifts_admin', $privileges));
                  Severity: Major
                  Found in includes/controller/user_shifts_controller.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                    return view_user_shifts();
                    Severity: Major
                    Found in includes/controller/user_shifts_controller.php - About 30 mins to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      elseif (isset($_REQUEST['save'])) {
                      if (! is_array($_SESSION['admin_shifts_shifts']) || ! is_array($_SESSION['admin_shifts_types']))
                      redirect(page_link_to('admin_shifts'));
                       
                      foreach ($_SESSION['admin_shifts_shifts'] as $shift) {
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 1 day to fix
                      includes/controller/admin_shifts_controller.php on lines 299..324

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      return page_with_title(_("Preview"), array(
                      form(array(
                      $hidden_types,
                      form_hidden('shifttype_id', $shifttype_id),
                      form_hidden('title', $title),
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 1 day to fix
                      includes/controller/admin_shifts_controller.php on lines 275..297

                      Identical blocks of code found in 2 locations. Consider refactoring.
                      Open

                      foreach ($shifts as $shift) {
                      $shifts_table_entry = [
                      'timeslot' => '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . '<br />' . Room_name_render(Room($shift['RID'])),
                      'title' => ShiftType_name_render(ShiftType($shifttype_id)) . ($shift['title'] ? '<br />' . $shift['title'] : ''),
                      'needed_angels' => ''
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 6 hrs to fix
                      includes/controller/admin_shifts_controller.php on lines 255..266

                      Identical blocks of code found in 2 locations. Consider refactoring.
                      Open

                      foreach ($types as $type) {
                      if (isset($_REQUEST['type_' . $type['id']]) && preg_match("/^[0-9]+$/", trim($_REQUEST['type_' . $type['id']]))) {
                      $needed_angel_types[$type['id']] = trim($_REQUEST['type_' . $type['id']]);
                      } else {
                      $ok = false;
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 2 hrs to fix
                      includes/controller/admin_shifts_controller.php on lines 149..156

                      Identical blocks of code found in 2 locations. Consider refactoring.
                      Open

                      if (isset($_REQUEST['shifttype_id'])) {
                      $shifttype = ShiftType($_REQUEST['shifttype_id']);
                      if ($shifttype === false)
                      engelsystem_error('Unable to load shift type.');
                      if ($shifttype == null) {
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 2 hrs to fix
                      includes/controller/admin_shifts_controller.php on lines 48..60

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      $shifts_row .= '<div class="pull-right">' . table_buttons(array(
                      button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
                      button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs'),
                      form_checkbox('del_shifts[] btn-xs', '', '', $value = $shift['SID'], false)
                      )). '</div>';
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 2 hrs to fix
                      includes/controller/user_shifts_controller.php on lines 878..882

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      $shift_row['info'] .= ' ' . table_buttons(array(
                      button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
                      button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs'),
                      form_checkbox('del_shifts[] btn-xs', '', '', $value = $shift['SID'], false)
                      ));
                      Severity: Major
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 2 hrs to fix
                      includes/controller/user_shifts_controller.php on lines 746..750

                      Identical blocks of code found in 2 locations. Consider refactoring.
                      Open

                      if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room_array[$_REQUEST['rid']]))
                      $rid = $_REQUEST['rid'];
                      else {
                      $ok = false;
                      $rid = $rooms[0]['RID'];
                      Severity: Minor
                      Found in includes/controller/user_shifts_controller.php and 1 other location - About 55 mins to fix
                      includes/controller/admin_shifts_controller.php on lines 66..72

                      There are no issues that match your filters.

                      Category
                      Status