YaleSTC/shifts

View on GitHub
app/controllers/shifts_controller.rb

Summary

Maintainability
D
1 day
Test Coverage

Method create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    parse_date_and_time_output(params[:shift])
    join_date_and_time(params[:shift])
    @shift = Shift.new(params[:shift])
    @shift.department = @shift.location.department
Severity: Minor
Found in app/controllers/shifts_controller.rb - About 2 hrs 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 create has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create
    parse_date_and_time_output(params[:shift])
    join_date_and_time(params[:shift])
    @shift = Shift.new(params[:shift])
    @shift.department = @shift.location.department
Severity: Minor
Found in app/controllers/shifts_controller.rb - About 1 hr to fix

    Method index has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def index
        @period_start = params[:date] ? Date.parse(params[:date]).previous_sunday : Date.today.previous_sunday
        @upcoming_shifts = Shift.where("user_id = ? and end > ? and department_id = ? and scheduled = ? and active = ?", current_user, Time.now.utc, current_department.id, true, true).order(:start).limit(5)
    
        # for user view preferences partial
    Severity: Minor
    Found in app/controllers/shifts_controller.rb - About 1 hr 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 default_email_group_settings has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def default_email_group_settings
        params[:email_group] ||= {}
        if params[:email_group]["start_time(1i)"]
          @start_time ||= DateTime.new(params[:email_group][:"start_time(1i)"].to_i,params[:email_group][:"start_time(2i)"].to_i,params[:email_group][:"start_time(3i)"].to_i,params[:email_group][:"start_time(4i)"].to_i,params[:email_group][:"start_time(5i)"].to_i)
        else
    Severity: Minor
    Found in app/controllers/shifts_controller.rb - About 1 hr 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 index has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def index
        @period_start = params[:date] ? Date.parse(params[:date]).previous_sunday : Date.today.previous_sunday
        @upcoming_shifts = Shift.where("user_id = ? and end > ? and department_id = ? and scheduled = ? and active = ?", current_user, Time.now.utc, current_department.id, true, true).order(:start).limit(5)
    
        # for user view preferences partial
    Severity: Minor
    Found in app/controllers/shifts_controller.rb - About 1 hr to fix

      Method update has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def update
          parse_date_and_time_output(params[:shift])
          join_date_and_time(params[:shift])
          @shift = Shift.find(params[:id])
          return unless user_is_owner_or_admin_of(@shift, @shift.department)
      Severity: Minor
      Found in app/controllers/shifts_controller.rb - About 1 hr to fix

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

            if params[:date].blank? and (current_user.user_config.view_week != "" and current_user.user_config.view_week != "whole_period")
              # only if default view and non-standard setting
              if current_user.user_config.view_week == "current_day"
                @day_collection = [Date.today]
              elsif current_user.user_config.view_week == "remainder"
        Severity: Major
        Found in app/controllers/shifts_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/calendars_controller.rb on lines 143..158

        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 73.

        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

            if params[:email_group]["end_time(1i)"]
              @end_time ||= DateTime.new(params[:email_group][:"end_time(1i)"].to_i,params[:email_group][:"end_time(2i)"].to_i,params[:email_group][:"end_time(3i)"].to_i,params[:email_group][:"end_time(4i)"].to_i,params[:email_group][:"end_time(5i)"].to_i)
            else
              @end_time ||= department_day_end_time
            end
        Severity: Minor
        Found in app/controllers/shifts_controller.rb and 1 other location - About 55 mins to fix
        app/controllers/shifts_controller.rb on lines 253..257

        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 45.

        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

            if params[:email_group]["start_time(1i)"]
              @start_time ||= DateTime.new(params[:email_group][:"start_time(1i)"].to_i,params[:email_group][:"start_time(2i)"].to_i,params[:email_group][:"start_time(3i)"].to_i,params[:email_group][:"start_time(4i)"].to_i,params[:email_group][:"start_time(5i)"].to_i)
            else
              @start_time ||= department_day_start_time
            end
        Severity: Minor
        Found in app/controllers/shifts_controller.rb and 1 other location - About 55 mins to fix
        app/controllers/shifts_controller.rb on lines 259..263

        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 45.

        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

                format.js do
                  error_string = ""
                  @shift.errors.each do |attr_name, message|
                    error_string += "<br><br>#{attr_name}: #{message}"
                  end
        Severity: Minor
        Found in app/controllers/shifts_controller.rb and 1 other location - About 15 mins to fix
        app/controllers/time_slots_controller.rb on lines 88..95

        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 26.

        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