YaleSTC/shifts

View on GitHub
app/controllers/sub_requests_controller.rb

Summary

Maintainability
B
4 hrs
Test Coverage

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

  def index
    if params[:shift_id]      # check if index listing is shift specific
      @shift=Shift.find(params[:shift_id])
      @subs=@shift.sub_requests
      @title_add=" for " + @shift.user.name + "'s shift in " + @shift.location.name + " on " + @shift.start.to_s(:gg)
Severity: Minor
Found in app/controllers/sub_requests_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 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    if params[:shift_id]      # check if index listing is shift specific
      @shift=Shift.find(params[:shift_id])
      @subs=@shift.sub_requests
      @title_add=" for " + @shift.user.name + "'s shift in " + @shift.location.name + " on " + @shift.start.to_s(:gg)
Severity: Minor
Found in app/controllers/sub_requests_controller.rb - About 1 hr to fix

    Method take has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def take
        @sub_request = SubRequest.find(params[:id])
        return unless require_department_membership(@sub_request.shift.department)
        #The form returns string values of "true" or "false", we must convert these to boolean
        just_mandatory = params[:sub_request][:mandatory_start] == "true" ? true : false
    Severity: Minor
    Found in app/controllers/sub_requests_controller.rb - About 45 mins 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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def update
        @sub_request = SubRequest.find(params[:id])
        return unless user_is_owner_or_admin_of(@sub_request.shift, current_department)
        begin
          SubRequest.transaction do
    Severity: Minor
    Found in app/controllers/sub_requests_controller.rb - About 35 mins 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 a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def create
        parse_date_and_time_output(params[:sub_request])
        join_date_and_time(params[:sub_request])
        @sub_request = SubRequest.new(params[:sub_request])
        @sub_request.shift = Shift.find(params[:shift_id])
    Severity: Minor
    Found in app/controllers/sub_requests_controller.rb - About 25 mins 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 new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def new
        shift = Shift.find_by_id(params[:shift_id])
        if shift && shift.scheduled? #avoids attempting to call for start times of a non-existant shift
          @sub_request = SubRequest.new(shift_id: params[:shift_id])
          @sub_request.mandatory_start = @sub_request.start = @sub_request.shift.start
    Severity: Minor
    Found in app/controllers/sub_requests_controller.rb - About 25 mins 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

    There are no issues that match your filters.

    Category
    Status