fossasia/engelsystem

View on GitHub
includes/controller/user_shifts_controller.php

Summary

Maintainability
F
3 wks
Test Coverage

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

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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 ($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 (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 ($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 view_user_shifts();
                  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 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

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 356.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 318.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 219.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 136.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 134.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 130.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 130.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      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

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 99.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status