testmycode/tmc-server

View on GitHub

Showing 278 of 278 total issues

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

  def self.write_points(ws, course, students, points)
    students.each do |student|
      row = student_row ws, student.login
      raise "student #{student.login} not found" if row < 0
      awarded = AwardedPoint.course_user_sheet_points(course, student, ws.title).map(&:name)
Severity: Minor
Found in lib/gdocs_export.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

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

        swagger_path '/api/v8/users/current/teacherships' do
          operation :get do
            key :description, 'Returns a list of organizations where the current user is a teacher'
            key :operationId, 'findTeachershipsForCurrentUser'
            key :produces, [
Severity: Major
Found in app/controllers/api/v8/users/teacherships_controller.rb and 6 other locations - About 1 hr to fix
app/controllers/api/v8/courses/all_courses_with_this_template_controller.rb on lines 9..31
app/controllers/api/v8/courses/submissions_controller.rb on lines 9..31
app/controllers/api/v8/courses/users/submissions_controller.rb on lines 40..62
app/controllers/api/v8/users/assistantships_controller.rb on lines 9..31
app/controllers/api/v8/users/assistantships_controller.rb on lines 38..60
app/controllers/api/v8/users/teacherships_controller.rb on lines 9..31

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

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

        awarded_points = exercise.points_for(current_user)
        completed = exercise.completed_by?(current_user)
        user_submissions = exercise.submissions_by(current_user)
        attempted = user_submissions.length > 0
        original_submission_date = user_submissions.pluck(:created_at).sort.first
Severity: Major
Found in lib/kafka_updater.rb and 1 other location - About 1 hr to fix
lib/kafka_updater.rb on lines 227..245

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

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

        swagger_path '/api/v8/users/current/assistantships' do
          operation :get do
            key :description, 'Returns a list of courses where the current user is an assistant'
            key :operationId, 'findAssistantshipsForCurrentUser'
            key :produces, [
Severity: Major
Found in app/controllers/api/v8/users/assistantships_controller.rb and 6 other locations - About 1 hr to fix
app/controllers/api/v8/courses/all_courses_with_this_template_controller.rb on lines 9..31
app/controllers/api/v8/courses/submissions_controller.rb on lines 9..31
app/controllers/api/v8/courses/users/submissions_controller.rb on lines 40..62
app/controllers/api/v8/users/assistantships_controller.rb on lines 9..31
app/controllers/api/v8/users/teacherships_controller.rb on lines 9..31
app/controllers/api/v8/users/teacherships_controller.rb on lines 38..60

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

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

      awarded_points = exercise.points_for(user)
      completed = exercise.completed_by?(user)
      user_submissions = exercise.submissions_by(user)
      attempted = user_submissions.length > 0
      original_submission_date = user_submissions.pluck(:created_at).sort.first
Severity: Major
Found in lib/kafka_updater.rb and 1 other location - About 1 hr to fix
lib/kafka_updater.rb on lines 147..165

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

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

        swagger_path '/api/v8/users/{user_id}/teacherships' do
          operation :get do
            key :description, 'Returns a list of organizations where the user is a teacher'
            key :operationId, 'findTeachershipsByUserId'
            key :produces, [
Severity: Major
Found in app/controllers/api/v8/users/teacherships_controller.rb and 6 other locations - About 1 hr to fix
app/controllers/api/v8/courses/all_courses_with_this_template_controller.rb on lines 9..31
app/controllers/api/v8/courses/submissions_controller.rb on lines 9..31
app/controllers/api/v8/courses/users/submissions_controller.rb on lines 40..62
app/controllers/api/v8/users/assistantships_controller.rb on lines 9..31
app/controllers/api/v8/users/assistantships_controller.rb on lines 38..60
app/controllers/api/v8/users/teacherships_controller.rb on lines 38..60

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

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

        swagger_path '/api/v8/users/{user_id}/assistantships' do
          operation :get do
            key :description, 'Returns a list of courses where the user is an assistant'
            key :operationId, 'findAssistantshipsByUserId'
            key :produces, [
Severity: Major
Found in app/controllers/api/v8/users/assistantships_controller.rb and 6 other locations - About 1 hr to fix
app/controllers/api/v8/courses/all_courses_with_this_template_controller.rb on lines 9..31
app/controllers/api/v8/courses/submissions_controller.rb on lines 9..31
app/controllers/api/v8/courses/users/submissions_controller.rb on lines 40..62
app/controllers/api/v8/users/assistantships_controller.rb on lines 38..60
app/controllers/api/v8/users/teacherships_controller.rb on lines 9..31
app/controllers/api/v8/users/teacherships_controller.rb on lines 38..60

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

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/core/exercises/{exercise_id}/submissions' do
            operation :post do
              key :description, 'Create submission from a zip file'
              key :operationId, 'createSubmission'
              key :produces, ['application/json']
app/controllers/api/v8/courses/exercises_controller.rb on lines 9..31

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

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

        swagger_path '/api/v8/courses/{course_id}/all_courses_with_this_template' do
          operation :get do
            key :description, 'Returns all courses with a same template in a json format'
            key :operationId, 'findAllCoursesWithThisTemplate'
            key :produces, [
app/controllers/api/v8/courses/submissions_controller.rb on lines 9..31
app/controllers/api/v8/courses/users/submissions_controller.rb on lines 40..62
app/controllers/api/v8/users/assistantships_controller.rb on lines 9..31
app/controllers/api/v8/users/assistantships_controller.rb on lines 38..60
app/controllers/api/v8/users/teacherships_controller.rb on lines 9..31
app/controllers/api/v8/users/teacherships_controller.rb on lines 38..60

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

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

          swagger_path '/api/v8/courses/{course_id}/users/current/submissions' do
            operation :get do
              key :description, "Returns the user's own submissions in a json format"
              key :operationId, 'findUsersOwnSubmissionsById'
              key :produces, [
app/controllers/api/v8/courses/all_courses_with_this_template_controller.rb on lines 9..31
app/controllers/api/v8/courses/submissions_controller.rb on lines 9..31
app/controllers/api/v8/users/assistantships_controller.rb on lines 9..31
app/controllers/api/v8/users/assistantships_controller.rb on lines 38..60
app/controllers/api/v8/users/teacherships_controller.rb on lines 9..31
app/controllers/api/v8/users/teacherships_controller.rb on lines 38..60

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

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/courses/{course_id}/exercises' do
          operation :get do
            key :description, 'Returns all exercises of the course as json. Course is searched by id'
            key :operationId, 'findExercisesById'
            key :produces, ['application/json']
Severity: Major
Found in app/controllers/api/v8/courses/exercises_controller.rb and 1 other location - About 1 hr to fix
app/controllers/api/v8/core/exercises/submissions_controller.rb on lines 12..34

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

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

        swagger_path '/api/v8/courses/{course_id}/submissions' do
          operation :get do
            key :description, 'Returns the submissions visible to the user in a json format'
            key :operationId, 'findSubmissionsById'
            key :produces, [
Severity: Major
Found in app/controllers/api/v8/courses/submissions_controller.rb and 6 other locations - About 1 hr to fix
app/controllers/api/v8/courses/all_courses_with_this_template_controller.rb on lines 9..31
app/controllers/api/v8/courses/users/submissions_controller.rb on lines 40..62
app/controllers/api/v8/users/assistantships_controller.rb on lines 9..31
app/controllers/api/v8/users/assistantships_controller.rb on lines 38..60
app/controllers/api/v8/users/teacherships_controller.rb on lines 9..31
app/controllers/api/v8/users/teacherships_controller.rb on lines 38..60

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

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 eligible_students has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

          def eligible_students
            unauthorize_guest!

            return respond_with_error("This feature is only for MOOC-organization's 2019 programming MOOC") unless params[:course_name] == '2019-ohjelmointi' && params[:organization_slug] == 'mooc'

    Method run has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run
        CourseTemplateRefresh.where(status: :not_started).each do |task|
          channel_id = task.course_template_id
          task.status = :in_progress
          task.save!
    Severity: Minor
    Found in app/background_tasks/refresh_course_task.rb - About 1 hr to fix

      Method update_course_progress has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def update_course_progress(task)
          finished_successfully = false
          course = Course.find(task.course_id)
          Rails.logger.info("Batch publishing progress 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 update_user_progress has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def update_user_progress(task)
            finished_successfully = false
            user = User.find(task.user_id)
            course = Course.find(task.course_id)
            Rails.logger.info("Publishing progress for user #{user.id} with moocfi id: #{course.moocfi_id}.")
        Severity: Minor
        Found in lib/kafka_updater.rb - About 1 hr to fix

          Method course_stats_show_submissions has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def course_stats_show_submissions
                return respond_not_found('No submissions yet') if @course.submissions.empty?
          
                @start_time =
                  if params[:start_time]
          Severity: Minor
          Found in app/controllers/stats_controller.rb - About 1 hr to fix

            Method index has 37 lines of code (exceeds 25 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

              Method for_submission has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.for_submission(submission)
                  Dir.mktmpdir do |tmpdir|
                    zip_path = "#{tmpdir}/submission.zip"
                    File.open(zip_path, 'wb') { |f| f.write(submission.return_file) }
                    SafeUnzipper.new.unzip(zip_path, tmpdir)
              Severity: Minor
              Found in app/models/source_file_list.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 update has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                def update
                  authorize! :update, @user
              
                  User.transaction do
                    @email_before = @user.email
              Severity: Minor
              Found in app/controllers/settings_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

              Severity
              Category
              Status
              Source
              Language