testmycode/tmc-server

View on GitHub

Showing 202 of 278 total issues

File submissions_controller.rb has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'submission_processor'

# Receives submissions and presents the full submission list and submission view.
# Also handles rerun requests.
class SubmissionsController < ApplicationController
Severity: Minor
Found in app/controllers/submissions_controller.rb - About 3 hrs to fix

    Method parse_condition has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_condition(str)
          if DateAndTimeUtils.looks_like_date_or_time(str)
            time = DateAndTimeUtils.to_time(str)
            raise 'Date out of range' if time.year > 10_000 || time.year < 1 # Prevent database datetime overflow
            raise "You can't have multiple unlock dates for the same exercise" if @datetime_count > 0 # Multiple unlock dates don't work correctly
    Severity: Minor
    Found in app/models/unlock_spec.rb - About 3 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 show has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def show
              @submission = Submission.find_by!(id: params[:id])
              unless @submission.processed?
                authorization_skip!
                sandbox_status = :created
    Severity: Major
    Found in app/controllers/api/v8/core/submissions_controller.rb - About 3 hrs to fix

      Method parse_condition has 74 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def parse_condition(str)
            if DateAndTimeUtils.looks_like_date_or_time(str)
              time = DateAndTimeUtils.to_time(str)
              raise 'Date out of range' if time.year > 10_000 || time.year < 1 # Prevent database datetime overflow
              raise "You can't have multiple unlock dates for the same exercise" if @datetime_count > 0 # Multiple unlock dates don't work correctly
      Severity: Major
      Found in app/models/unlock_spec.rb - About 2 hrs to fix

        File user.rb has 289 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        class User < ApplicationRecord
          include Comparable
          include Gravtastic
          include Swagger::Blocks
          gravtastic
        Severity: Minor
        Found in app/models/user.rb - About 2 hrs to fix

          Method show has 70 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def show
              @course ||= @submission.course
              @exercise ||= @submission.exercise
              @organization = @course.organization
          
          
          Severity: Major
          Found in app/controllers/submissions_controller.rb - About 2 hrs to fix

            Method respond_with_error has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                def respond_with_error(msg, code = 500, exception = nil, extra_json_keys = {})
                  respond_to do |format|
                    format.html do
                      render 'shared/respond_with_error',
                             locals: { message: ERB::Util.html_escape(msg), exception: exception },
            Severity: Minor
            Found in app/controllers/application_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 submission_review_column has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

              def submission_review_column(submission)
                if submission.reviewed?
                  if can? :create_review, submission.course
                    link_to 'Available', new_submission_review_path(submission)
                  else
            Severity: Minor
            Found in app/helpers/submissions_helper.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 refresh has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.refresh(course_template_refresh_task)
                course_template = course_template_refresh_task.course_template
                command = "#{self.langs_executable_path}/current refresh-course"\
                " --cache-path #{course_template.cache_path}"\
                " --cache-root #{Course.cache_root}"\
            Severity: Minor
            Found in lib/rust_langs_cli_executor.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 visible_to? has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

              def visible_to?(user, ignore_email_verification = false)
                if user.administrator?
                  true
                elsif !ignore_email_verification && !user.email_verified?
                  false
            Severity: Minor
            Found in app/models/solution.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_available_points has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

                  def update_available_points
                    @rust_data['exercises'].each do |exercise|
                      added = []
                      removed = []
            
            
            Severity: Minor
            Found in lib/course_refresh_database_updater.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 63 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                      def create
                        unauthorize_guest!
            
                        @exercise = Exercise.find(params[:exercise_id])
                        authorize! :read, @exercise
            Severity: Major
            Found in app/controllers/api/v8/core/exercises/submissions_controller.rb - About 2 hrs to fix

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

                def index
                  if params[:course_id]
                    @course = Course.find(params[:course_id])
                    @parent = @course
                    @numeric_stats = @course.exercises.where(hidden: false).sort.map do |ex|
              Severity: Major
              Found in app/controllers/feedback_answers_controller.rb - About 2 hrs to fix

                Class ApplicationController has 22 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class ApplicationController < ActionController::Base
                  include BreadCrumbs
                
                  helper :all
                
                
                Severity: Minor
                Found in app/controllers/application_controller.rb - About 2 hrs to fix

                  Method show has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                            def show
                              authorization_skip!
                              organization = Organization.find_by!(slug: params[:organization_slug])
                              course = organization.courses.find_by(name: "#{params[:organization_slug]}-#{params[:course_name]}")
                              course = organization.courses.find_by!(name: params[:course_name]) unless course
                  Severity: Major
                  Found in app/controllers/api/v8/organizations/courses/exercises_controller.rb - About 2 hrs to fix

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

                      def create
                        if !params[:submission] || !params[:submission][:file]
                          return respond_not_found('No ZIP file selected or failed to receive it')
                        end
                    
                    
                    Severity: Major
                    Found in app/controllers/submissions_controller.rb - About 2 hrs to fix

                      Class CoursesController has 21 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      class CoursesController < ApplicationController
                        before_action :set_organization
                        before_action :set_course, except: %i[help index show_json]
                      
                        skip_authorization_check only: [:index]
                      Severity: Minor
                      Found in app/controllers/courses_controller.rb - About 2 hrs to fix

                        Method update_course_points has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def update_course_points(task)
                            finished_successfully = false
                            course = Course.find(task.course_id)
                            Rails.logger.info("Batch publishing points for course #{course.name} with moocfi id: #{course.moocfi_id}")
                            if !course.moocfi_id
                        Severity: Minor
                        Found in lib/kafka_updater.rb - About 1 hr to fix

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

                                  def index
                                    unauthorize_guest!
                                    exercise = Exercise.find(params[:exercise_id])
                                    course = exercise.course
                                    authorize! :read, exercise
                          Severity: Minor
                          Found in app/controllers/api/v8/exercises/model_solutions_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 run has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def run
                              Rails.logger.info('Creating directory vendor/tmc-langs-rust') unless File.directory?('vendor/tmc-langs-rust')
                              Dir.mkdir('vendor/tmc-langs-rust') unless File.directory?('vendor/tmc-langs-rust')
                          
                              executable = "vendor/tmc-langs-rust/tmc-langs-cli-x86_64-unknown-linux-gnu-#{@@rust_langs_version}"
                          Severity: Minor
                          Found in app/background_tasks/rust_langs_downloader_task.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

                          Severity
                          Category
                          Status
                          Source
                          Language