crowdAI/crowdai

View on GitHub
app/controllers/api/external_graders_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

File external_graders_controller.rb has 360 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Api::ExternalGradersController < Api::BaseController
  before_action :auth_by_api_key, only: [:show, :update]
  before_action :auth_by_api_key_and_client_id, only: [:create]

  def show #GET
Severity: Minor
Found in app/controllers/api/external_graders_controller.rb - About 4 hrs to fix

    Method create has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create #POST
        Rails.logger.info "[api] Api::ExternalGradersController#create"
        Rails.logger.info "[api] params: #{params}"
        message = nil
        status = nil
    Severity: Major
    Found in app/controllers/api/external_graders_controller.rb - About 2 hrs to fix

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

        def update #PATCH
          Rails.logger.info "[api] Api::ExternalGradersController#update"
          Rails.logger.info "[api] params: #{params}"
          message = nil
          status = nil
      Severity: Major
      Found in app/controllers/api/external_graders_controller.rb - About 2 hrs to fix

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

          def create #POST
            Rails.logger.info "[api] Api::ExternalGradersController#create"
            Rails.logger.info "[api] params: #{params}"
            message = nil
            status = nil
        Severity: Minor
        Found in app/controllers/api/external_graders_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 update has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def update #PATCH
            Rails.logger.info "[api] Api::ExternalGradersController#update"
            Rails.logger.info "[api] params: #{params}"
            message = nil
            status = nil
        Severity: Minor
        Found in app/controllers/api/external_graders_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 grading_params has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def grading_params
            case params[:grading_status]
            when 'graded'
              if params[:grading_message].blank?
                grading_message = 'Graded successfully'
        Severity: Minor
        Found in app/controllers/api/external_graders_controller.rb - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

              unless (media_large.present? && media_thumbnail.present? && media_content_type.present?) || (media_large.blank? && media_thumbnail.blank? && media_content_type.blank?)
                raise MediaFieldsIncomplete
              end
          Severity: Major
          Found in app/controllers/api/external_graders_controller.rb - About 40 mins to fix

            Method media_fields_present? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def media_fields_present?
                media_large = params[:media_large]
                media_thumbnail = params[:media_thumbnail]
                media_content_type = params[:media_content_type]
                unless (media_large.present? && media_thumbnail.present? && media_content_type.present?) || (media_large.blank? && media_thumbnail.blank? && media_content_type.blank?)
            Severity: Minor
            Found in app/controllers/api/external_graders_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

            Avoid too many return statements within this method.
            Open

                  return false
            Severity: Major
            Found in app/controllers/api/external_graders_controller.rb - About 30 mins to fix

              Method get_challenge_round_id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_challenge_round_id(challenge:, params:)
                  if params[:challenge_round_id].present?
                    round = ChallengeRound.where(
                      challenge_id: challenge.id,
                      id: params[:challenge_round_id]).first
              Severity: Minor
              Found in app/controllers/api/external_graders_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 grading_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def grading_params
                  case params[:grading_status]
                  when 'graded'
                    if params[:grading_message].blank?
                      grading_message = 'Graded successfully'
              Severity: Minor
              Found in app/controllers/api/external_graders_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