testmycode/tmc-server

View on GitHub

Showing 278 of 278 total issues

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

          swagger_path '/api/v8/courses/{course_id}/submissions/last_hour' do
            operation :get do
              key :description, 'Returns submissions to the course in the latest hour'
              key :produces, ['application/json']
              key :tags, ['submission']
app/controllers/api/v8/core/organizations/courses_controller.rb on lines 10..24
app/controllers/api/v8/courses/points_controller.rb on lines 9..23
app/controllers/api/v8/courses/users/points_controller.rb on lines 31..45

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

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_exercise_checksums has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def update_exercise_checksums
        @rust_data['exercises'].each do |exercise|
          ex = @course.exercises.find { |e| e.name == exercise['name'] }
          next unless ex
          if ex.checksum != exercise['checksum']
Severity: Minor
Found in lib/course_refresh_database_updater.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 4 locations. Consider refactoring.
Open

          swagger_path '/api/v8/core/org/{organization_slug}/courses' do
            operation :get do
              key :description, "Returns an array containing each course's collection of links"
              key :produces, ['application/json']
              key :tags, ['core']
app/controllers/api/v8/courses/points_controller.rb on lines 9..23
app/controllers/api/v8/courses/submissions/last_hour_controller.rb on lines 10..24
app/controllers/api/v8/courses/users/points_controller.rb on lines 31..45

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

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 save_results has a Cognitive Complexity of 10 (exceeds 5 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

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 <=> has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def <=>(other)
    if other.is_a?(Version)
      p1 = parts.clone
      p2 = other.parts.clone
      p1 << 0 while p1.length < p2.length
Severity: Minor
Found in lib/version.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 create has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def create
        authorize! :create, User

        @user = User.new

Severity: Minor
Found in app/controllers/api/v8/users_controller.rb - About 1 hr to fix

    Method visible_to? has 27 lines of code (exceeds 25 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 1 hr to fix

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

        def run
          return unless @kafka_bridge_url && @kafka_bridge_secret && @service_id
          return if @kafka_bridge_url.empty? || @kafka_bridge_secret.empty? || @service_id.empty?
          KafkaBatchUpdatePoints.where(realtime: true).each do |task|
            finished_successfully = false
      Severity: Minor
      Found in app/background_tasks/kafka_realtime_update_points_task.rb - About 1 hr to fix

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

          def show
            if params[:username].present? && params[:session_id].present?
              user = User.find_by(login: params[:username])
              user ||= User.find_by('lower(email) = ?', params[:username].downcase)
              # Allows using oauth2 tokens of the new api for authenticating
        Severity: Minor
        Found in app/controllers/auths_controller.rb - About 1 hr to fix

          Method update_available_points has 27 lines of code (exceeds 25 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 1 hr to fix

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

              def run
                return unless @kafka_bridge_url && @kafka_bridge_secret && @service_id
                return if @kafka_bridge_url.empty? || @kafka_bridge_secret.empty? || @service_id.empty?
                KafkaBatchUpdatePoints.where(realtime: false).each do |task|
                  finished_successfully = false
            Severity: Minor
            Found in app/background_tasks/kafka_batch_update_points_task.rb - About 1 hr to fix

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

                def show
                  course_id = params[:course_id]
                  user_id = params[:id]
              
                  course = Course.where(id: course_id).first || Course.where(name: course_id).first
              Severity: Minor
              Found in app/controllers/exercise_status_controller.rb - About 1 hr to fix

                Method extra_field has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def extra_field(field_value, method_options)
                    field = field_value.field
                
                    return '' if field.options[:hidden]
                    return raw(field.label) if field.field_type == :html
                Severity: Minor
                Found in app/helpers/extra_field_helper.rb - About 1 hr to fix

                  Method sh! has 26 lines of code (exceeds 25 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

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

                            swagger_path '/api/v8/core/submissions/{submission_id}/download' do
                              operation :get do
                                key :description, 'Download the submission as a zip file'
                                key :operationId, 'downloadSubmission'
                                key :produces, ['application/zip']
                    Severity: Minor
                    Found in app/controllers/api/v8/core/submissions_controller.rb and 1 other location - About 1 hr to fix
                    app/controllers/api/v8/core/exercises/solutions_controller.rb on lines 10..25

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

                    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}/solution/download' do
                                operation :get do
                                  key :description, 'Download the solution for an exercise as a zip file'
                                  key :operationId, 'downloadSolution'
                                  key :produces, ['application/zip']
                    app/controllers/api/v8/core/submissions_controller.rb on lines 9..24

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

                    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

                      def submission_queue_times
                        created_at = Submission.arel_table[:created_at]
                        results = Submission
                                  .select("COUNT(id), extract(epoch from avg(processing_began_at - created_at)) as avg_duration,  stddev_samp(extract(epoch from processing_completed_at - processing_began_at)) as stddev, date_trunc('minute', created_at) as minute") .where.not(processing_began_at: nil) .where(created_at.gteq(1.month.ago)) .group("date_trunc('minute', created_at)") .order("date_trunc('minute', created_at) DESC")
                    
                    
                    Severity: Minor
                    Found in app/controllers/api/beta/stats_controller.rb and 1 other location - About 55 mins to fix
                    app/controllers/api/beta/stats_controller.rb on lines 6..23

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

                    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

                            def set_password
                              user_params = params[:user]
                              if user_params[:password].blank?
                                @user.errors.add(:password, 'needed')
                              elsif user_params[:password].length > 1000
                    Severity: Minor
                    Found in app/controllers/api/v8/users_controller.rb and 1 other location - About 55 mins to fix
                    app/controllers/users_controller.rb on lines 168..178

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

                    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

                      def submission_processing_times
                        processing_began_at = Submission.arel_table[:processing_began_at]
                        results = Submission
                                  .select("COUNT(id), extract(epoch from avg(processing_completed_at - processing_began_at)) as avg_duration, stddev_samp(extract(epoch from processing_completed_at - processing_began_at)) as stddev, date_trunc('minute', processing_began_at) as minute")
                                  .where.not(processing_began_at: nil)
                    Severity: Minor
                    Found in app/controllers/api/beta/stats_controller.rb and 1 other location - About 55 mins to fix
                    app/controllers/api/beta/stats_controller.rb on lines 26..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 46.

                    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

                        def set_password
                          user_params = params[:user]
                          if user_params[:password].blank?
                            @user.errors.add(:password, 'needed')
                          elsif user_params[:password].length > 1000
                    Severity: Minor
                    Found in app/controllers/users_controller.rb and 1 other location - About 55 mins to fix
                    app/controllers/api/v8/users_controller.rb on lines 177..187

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

                    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