testmycode/tmc-server

View on GitHub

Showing 278 of 278 total issues

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

              swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/exercises/{exercise_name}/users/current/points' do
                operation :get do
                  key :description, 'Returns all the awarded points of an excercise for current user'
                  key :operationId, 'findCurrentUsersAwardedPointsByCourseNameAndExerciseName'
                  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/points_controller.rb on lines 11..35

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

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

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

      def index
        if @organization.nil?
          authorize! :view, :participants_list
          courses = Course.all
          users = User.all
    Severity: Minor
    Found in app/controllers/participants_controller.rb - About 1 hr to fix

      Method bootstrap_flash has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def bootstrap_flash
          flash_messages = []
          flash.each do |type, message|
            # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
            next if message.blank?
      Severity: Minor
      Found in app/helpers/bootstrap_flash_helper.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 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          @course = Course.find(params[:course_id])
          authorize! :see_points, @course
          return respond_unauthorized('Authentication required') if current_user.guest?
          add_course_breadcrumb
      Severity: Minor
      Found in app/controllers/points_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 show has a Cognitive Complexity of 14 (exceeds 5 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

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

        def self.save_results(submission, results)
          ActiveRecord::Base.transaction do
            raise InvalidTokenError, 'Invalid or expired token' if results['token'] != submission.secret_token
      
            submission.all_tests_passed = false
      Severity: Minor
      Found in lib/sandbox_results_saver.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}/points' do
                    operation :get do
                      key :description, 'Returns all the awarded points of an excercise for all users'
                      key :operationId, 'findAllAwardedPointsByCourseIdAndExerciseName'
                      key :produces, ['application/json']
        app/controllers/api/v8/courses/exercises/users/points_controller.rb on lines 38..61
        app/controllers/api/v8/organizations/courses/exercises_controller.rb on lines 10..33

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

        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}/submissions' do
                    operation :get do
                      key :description, 'Returns the submissions visible to the user in a json format'
                      key :operationId, 'findSubmissions'
                      key :produces, [
        app/controllers/api/v8/courses/users/submissions_controller.rb on lines 10..33
        app/controllers/api/v8/organizations/courses/users/submissions_controller.rb on lines 42..65

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

        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/courses/{course_id}/exercises/{exercise_name}/users/current/points' do
                      operation :get do
                        key :description, 'Returns all the awarded points of an excercise for current user'
                        key :operationId, 'findCurrentUsersAwardedPointsByCourseIdAndExerciseName'
                        key :produces, ['application/json']
        app/controllers/api/v8/courses/exercises/points_controller.rb on lines 10..33
        app/controllers/api/v8/organizations/courses/exercises_controller.rb on lines 10..33

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

        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' do
                    operation :get do
                      key :description, 'Returns all exercises of the course as json. Course is searched by name'
                      key :operationId, 'findExercisesByName'
                      key :produces, ['application/json']
        app/controllers/api/v8/courses/exercises/points_controller.rb on lines 10..33
        app/controllers/api/v8/courses/exercises/users/points_controller.rb on lines 38..61

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

        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}/users/current/submissions' do
                      operation :get do
                        key :description, "Returns the user's own submissions in a json format"
                        key :operationId, 'findUsersOwnSubmissionsByCourseName'
                        key :produces, [
        app/controllers/api/v8/courses/users/submissions_controller.rb on lines 10..33
        app/controllers/api/v8/organizations/courses/submissions_controller.rb on lines 10..33

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

        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/courses/{course_id}/users/{user_id}/submissions' do
                    operation :get do
                      key :description, 'Returns the submissions visible to the user in a json format'
                      key :operationId, 'findUsersSubmissionsById'
                      key :produces, [
        app/controllers/api/v8/organizations/courses/submissions_controller.rb on lines 10..33
        app/controllers/api/v8/organizations/courses/users/submissions_controller.rb on lines 42..65

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

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

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

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

              def maybe_update_password(user, user_params)
                if user_params[:old_password].present? || user_params[:password].present?
                  if !user.has_password?(user_params[:old_password])
                    user.errors.add(:old_password, 'incorrect')
                  elsif user_params[:password] != user_params[:password_repeat]
          Severity: Major
          Found in app/controllers/settings_controller.rb and 1 other location - About 1 hr to fix
          app/controllers/users_controller.rb on lines 181..197

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

          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

              def maybe_update_password(user, user_params)
                if user_params[:old_password].present? || user_params[:password].present?
                  if !user.has_password?(user_params[:old_password])
                    user.errors.add(:old_password, 'incorrect')
                  elsif user_params[:password] != user_params[:password_repeat]
          Severity: Major
          Found in app/controllers/users_controller.rb and 1 other location - About 1 hr to fix
          app/controllers/settings_controller.rb on lines 88..104

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

          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

          Function makeToc has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function makeToc($targetElement) {
            function makeId(text) {
                return text.replace(/[^_a-zA-Z0-9]+/ig, '_').toLowerCase();
            }
          
          
          Severity: Minor
          Found in doc/usermanual/js/toc.js - About 1 hr to fix

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

                    def check_client_minimum_version(client_name, client_version)
                      begin
                        client_version = Version.new(client_version) unless client_version.nil?
                      rescue StandardError
                        raise "\nInvalid version string: #{client_version}\n"
            Severity: Minor
            Found in app/controllers/api/v8/base_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 check_client_version has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def check_client_version(client_name, client_version)
                  begin
                    client_version = Version.new(client_version) unless client_version.nil?
                  rescue StandardError
                    raise "Invalid version string: #{client_version}"
            Severity: Minor
            Found in app/controllers/application_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 sh! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def sh!(*args)
                options = {
                  assert_silent: false,
                  escape: true,
                  timeout: nil
            Severity: Minor
            Found in lib/system_commands.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