testmycode/tmc-server

View on GitHub

Showing 278 of 278 total issues

Method course_stats_show_submissions has a Cognitive Complexity of 12 (exceeds 5 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

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

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

    def assign_show_view_vars
      @exercises = @course.exercises.includes(:course)
      @exercises.preload(:unlocks).where(unlocks: { user: current_user })
      @exercises = @exercises.select { |ex| ex.visible_to?(current_user) }
                             .natsort_by(&:name)
Severity: Minor
Found in app/controllers/courses_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 refresh_course has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def refresh_course(course, data)
        @report = Report.new
        @rust_data = data['output-data']
        Course.transaction(requires_new: true) do
          @course = Course.find(course.id)
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

Method load_fields has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.load_fields(kind, config_file_path)
      return [] unless File.exist?(config_file_path)

      kind = kind.to_s

Severity: Minor
Found in app/models/extra_field.rb - About 1 hr to fix

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

                swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/users/{user_id}/points' do
                  operation :get do
                    key :description, "Returns the given user's points from the course in a json format. Course is searched by name"
                    key :produces, ['application/json']
                    key :tags, ['point']
    app/controllers/api/v8/organizations/courses/users/points_controller.rb on lines 11..27

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

    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

                swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/users/{user_id}/points' do
                  operation :get do
                    key :description, "Returns the given user's points from the course in a json format. Course is searched by name"
                    key :produces, ['application/json']
                    key :tags, ['point']
    app/controllers/api/v8/organizations/courses/users/progress_controller.rb on lines 11..27

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

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

        def check_access!
          if current_user.guest?
            raise CanCan::AccessDenied
          end
    
    
    Severity: Minor
    Found in app/controllers/submissions_controller.rb - About 1 hr to fix

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

        def index
          if params[:course_id]
            fetch :course
            @organization = @course.organization
            @my_reviews = @course.submissions
      Severity: Minor
      Found in app/controllers/reviews_controller.rb - About 1 hr to fix

        Method submission_review_column has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def submission_review_column(submission)
            if submission.reviewed?
              if can? :create_review, submission.course
                link_to 'Available', new_submission_review_path(submission)
              else
        Severity: Minor
        Found in app/helpers/submissions_helper.rb - About 1 hr to fix

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

            Method course_data has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def course_data(organization, course, opts = {})
                @course = course
                data = {
                  id: course.id,
                  name: course.name,
            Severity: Minor
            Found in lib/course_list.rb - About 1 hr to fix

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

                      def create
                        return respond_forbidden unless current_user.administrator?
                        users = if params[:extra_fields]
                          User.eager_load(:user_field_values).where(login: params[:usernames])
                        else
              Severity: Minor
              Found in app/controllers/api/v8/users/basic_info_by_usernames_controller.rb - About 1 hr to fix

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

                        def create
                          return respond_forbidden unless current_user.administrator?
                          users = if params[:extra_fields]
                            User.eager_load(:user_field_values).where(id: params[:ids])
                          else
                Severity: Minor
                Found in app/controllers/api/v8/users/basic_info_by_ids_controller.rb - About 1 hr to fix

                  Method exercise_data has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def exercise_data(exercise)
                        return nil unless exercise.visible_to?(@user)
                  
                        # optimization: use @unlocked_exercises to avoid querying unlocks repeatedly
                        locked = exercise.requires_unlock? && !@unlocked_exercises.include?(exercise.name)
                  Severity: Minor
                  Found in lib/course_info.rb - About 1 hr to fix

                    Method run has a Cognitive Complexity of 11 (exceeds 5 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

                    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 11 (exceeds 5 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

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

                      def print_setup_phases(phase = 0)
                        update_setup_phase(phase) unless phase == 2
                        maxphase = setup_in_progress? ? session[:ongoing_course_setup][:phase] : phase
                        STEPS.each_with_index do |st, i|
                          path = nil
                    Severity: Minor
                    Found in app/controllers/setup/setup_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 create has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def create
                        authorize! :teach, @organization
                    
                        custom = params[:course][:course_template_id].blank?
                    
                    
                    Severity: Minor
                    Found in app/controllers/setup/course_details_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