testmycode/tmc-server

View on GitHub

Showing 278 of 278 total issues

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

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

        if !include_admins && only_for_user
          query.join(users).on(users[:id].eq(awarded_points[:user_id]), users[:administrator].eq(false), users[:legitimate_student].eq(true)).where(users[:id].eq(only_for_user.id))
        elsif !include_admins
          query.join(users).on(users[:id].eq(awarded_points[:user_id]), users[:administrator].eq(false), users[:legitimate_student].eq(true))
        elsif only_for_user
    Severity: Major
    Found in app/models/awarded_point.rb and 1 other location - About 2 hrs to fix
    app/models/awarded_point.rb on lines 129..135

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

    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 !include_admins && only_for_user
          query.join(users).on(users[:id].eq(awarded_points[:user_id]), users[:administrator].eq(false), users[:legitimate_student].eq(true)).where(users[:id].eq(only_for_user.id))
        elsif !include_admins
          query.join(users).on(users[:id].eq(awarded_points[:user_id]), users[:administrator].eq(false), users[:legitimate_student].eq(true))
        elsif only_for_user
    Severity: Major
    Found in app/models/awarded_point.rb and 1 other location - About 2 hrs to fix
    app/models/awarded_point.rb on lines 90..96

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

    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

                output = output.merge(
                  case @submission.status(current_user)
                  when :processing then {
                    submissions_before_this: @submission.unprocessed_submissions_before_this,
                    total_unprocessed: Submission.unprocessed_count
    Severity: Major
    Found in app/controllers/api/v8/core/submissions_controller.rb and 1 other location - About 2 hrs to fix
    app/controllers/submissions_controller.rb on lines 74..97

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

    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

            output = output.merge(
              case @submission.status(current_user)
              when :processing then {
                submissions_before_this: @submission.unprocessed_submissions_before_this,
                total_unprocessed: Submission.unprocessed_count
    Severity: Major
    Found in app/controllers/submissions_controller.rb and 1 other location - About 2 hrs to fix
    app/controllers/api/v8/core/submissions_controller.rb on lines 83..106

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

    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

    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

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

              def index
                unauthorize_guest!
                course = Course.find_by!(id: params[:course_id]) if params[:course_id]
                can_see_everything = current_user.administrator? || current_user.teacher?(course.organization) || current_user.assistant?(course)
                authorize! :read, course
      Severity: Minor
      Found in app/controllers/api/v8/courses/exercises_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

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

            finished_successfully = false
            begin
              type = @updater.task_type(task)
              case type
              when 'user_progress'
      Severity: Major
      Found in app/background_tasks/kafka_realtime_update_points_task.rb and 1 other location - About 1 hr to fix
      app/background_tasks/kafka_batch_update_points_task.rb on lines 17..39

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

      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

            finished_successfully = false
            begin
              type = @updater.task_type(task)
              case type
              when 'user_progress'
      Severity: Major
      Found in app/background_tasks/kafka_batch_update_points_task.rb and 1 other location - About 1 hr to fix
      app/background_tasks/kafka_realtime_update_points_task.rb on lines 17..39

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

      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

              swagger_path '/api/v8/users/basic_info_by_usernames' do
                operation :post do
                  key :description, "Find all users' basic infos with the posted json array of usernames"
                  key :operationId, 'findUsersBasicInfoByUsernames'
                  parameter do
      app/controllers/api/v8/users/basic_info_by_emails_controller.rb on lines 9..40

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

      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

              swagger_path '/api/v8/users/basic_info_by_emails' do
                operation :post do
                  key :description, "Find all users' basic infos with the posted json array of emails"
                  key :operationId, 'findUsersBasicInfoByEmails'
                  parameter do
      app/controllers/api/v8/users/basic_info_by_usernames_controller.rb on lines 9..40

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

      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

      Method send_submission has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def send_submission(submission, notify_url)
          exercise = submission.exercise
      
          raise 'Submission has no secret token' if submission.secret_token.blank?
          raise "Exercise #{submission.exercise_name} for submission gone. Cannot resubmit." if exercise.nil?
      Severity: Minor
      Found in app/models/remote_sandbox.rb - About 1 hr to fix

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

          def update
            authorize! :teach, @organization
        
            print_setup_phases(3)
        
        
        Severity: Minor
        Found in app/controllers/setup/course_timings_controller.rb - About 1 hr to fix

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

            def show
              @exercise = Exercise.find(params[:id])
              @course = Course.lock('FOR SHARE').find(@exercise.course_id)
              @organization = @course.organization
              authorize! :read, @course
          Severity: Minor
          Found in app/controllers/exercises_controller.rb - About 1 hr to fix

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

              def show
                @user = User.find(params[:id])
                authorize! :view_participant_information, @user
                # TODO: bit ugly -- and now it's even worse!
                @awarded_points =
            Severity: Minor
            Found in app/controllers/participants_controller.rb - About 1 hr to fix

              Method email_confirmation has 46 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def email_confirmation(user, origin = nil, language = nil)
                  @origin = origin
                  @user = user
                  token = user.verification_tokens.email.create!
                  @url = confirm_email_url(@user.id, token.token, language: language)
              Severity: Minor
              Found in app/mailers/user_mailer.rb - About 1 hr to fix

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                            swagger_path '/api/v8/courses/{course_id}/exercises/{exercise_name}/users/{user_id}/points' do
                              operation :get do
                                key :description, 'Returns all the awarded points of an excercise for the specified user'
                                key :operationId, 'findUsersAwardedPointsByCourseIdAndExerciseName'
                                key :produces, ['application/json']
                app/controllers/api/v8/organizations/courses/exercises/points_controller.rb on lines 11..35
                app/controllers/api/v8/organizations/courses/exercises/users/points_controller.rb on lines 12..36

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

                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 3 locations. Consider refactoring.
                Open

                            swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/exercises/{exercise_name}/points' do
                              operation :get do
                                key :description, 'Returns all the awarded points of an excercise for all users'
                                key :operationId, 'findAllAwardedPointsByCourseNameAndExerciseName'
                                key :produces, ['application/json']
                app/controllers/api/v8/courses/exercises/users/points_controller.rb on lines 11..35
                app/controllers/api/v8/organizations/courses/exercises/users/points_controller.rb on lines 12..36

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

                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

                Severity
                Category
                Status
                Source
                Language