testmycode/tmc-server

View on GitHub

Showing 278 of 278 total issues

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

  def create
    submission = Submission.find(params[:submission_id])
    authorize! :read, submission

    answer_params = params[:answers]
Severity: Minor
Found in app/controllers/feedback_answers_controller.rb - About 1 hr to fix

    Method course_points has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.course_points(course, include_admins = false, hidden = false, only_for_user = nil)
        awarded_points = AwardedPoint.arel_table
        users = User.arel_table
        exercises = Exercise.arel_table
        submissions = Submission.arel_table
    Severity: Minor
    Found in app/models/awarded_point.rb - About 1 hr to fix

      Method difference_with_solution has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def difference_with_solution
          @course ||= @submission.course
          authorize! :teach, @course
          @exercise ||= @submission.exercise
          @organization = @course.organization
      Severity: Minor
      Found in app/controllers/submissions_controller.rb - About 1 hr to fix

        Method index_csv has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def index_csv
              CSV.generate(force_quotes: true) do |csv|
                title_row = (@ordinary_fields + @extra_fields.map(&:name)).select { |f| @visible_columns.include?(f) }.map(&:humanize)
        
                if @group_completion
        Severity: Minor
        Found in app/controllers/participants_controller.rb - About 1 hr to fix

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

            def run
              Rails.logger.info('Creating directory vendor/tmc-langs-rust') unless File.directory?('vendor/tmc-langs-rust')
              Dir.mkdir('vendor/tmc-langs-rust') unless File.directory?('vendor/tmc-langs-rust')
          
              executable = "vendor/tmc-langs-rust/tmc-langs-cli-x86_64-unknown-linux-gnu-#{@@rust_langs_version}"
          Severity: Minor
          Found in app/background_tasks/rust_langs_downloader_task.rb - About 1 hr to fix

            Method filter_fields! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.filter_fields!(submissions)
                submissions.map! do |sub|
                  {
                    id: sub.id,
                    user_id: sub.user_id,
            Severity: Minor
            Found in app/models/submission.rb - About 1 hr to fix

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

                    def show
                      unauthorize_guest! if current_user.guest?
                      user = current_user
                      user = User.find_by!(id: params[:id]) unless params[:id] == 'current'
                      authorize! :read, user
              Severity: Minor
              Found in app/controllers/api/v8/users_controller.rb - About 1 hr to fix

                Method update_user_points has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def update_user_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

                  Method exercise_data_core_api has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def exercise_data_core_api(exercise)
                        # optimization: use @unlocked_exercises to avoid querying unlocks repeatedly
                        locked = exercise.requires_unlock? && !@unlocked_exercises.include?(exercise.name)
                        show_points = !exercise.hide_submission_results? && !exercise.course.hide_submission_results?
                        attempted = exercise.attempted_by?(@user)
                  Severity: Minor
                  Found in lib/course_info.rb - About 1 hr to fix

                    Method update has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def update
                            unauthorize_guest! if current_user.guest?
                    
                            User.transaction do
                              @user = current_user
                    Severity: Minor
                    Found in app/controllers/api/v8/users_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 find_all_files_under has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def self.find_all_files_under(root_dir)
                          files = []
                          total_size = 0
                          Pathname(root_dir).realpath.find do |file|
                            next unless file.size <= MAX_INDIVIDUAL_FILE_SIZE
                    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 index has a Cognitive Complexity of 10 (exceeds 5 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

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

                      def confirm_email
                        language = params[:language]
                        VerificationToken.unscoped.email.find_by!(user_id: params[:user_id], token: params[:id])
                        redirect_path = root_url
                        redirect_path = "https://course.elementsofai.com/#{language && language != "en" ? "#{language}/" : ''}email-verification" if params[:origin] && params[:origin].start_with?('elements_of_ai')
                    Severity: Minor
                    Found in app/controllers/users_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 10 (exceeds 5 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

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

                    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 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def create
                        authorize! :modify_assistants, @course
                    
                        if params[:commit] == 'Add new assistant'
                          new_assistant = User.find_by('lower(email) = ?', assistant_params[:email].downcase)
                    Severity: Minor
                    Found in app/controllers/setup/course_assistants_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 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                              def show
                                authorization_skip!
                                organization = Organization.find_by!(slug: params[:organization_slug])
                                course = organization.courses.find_by(name: "#{params[:organization_slug]}-#{params[:course_name]}")
                                course = organization.courses.find_by!(name: params[:course_name]) unless course

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

                    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/courses/{course_id}/users/current/points' do
                                operation :get do
                                  key :description, "Returns the current user's points from the course in a json format. Course is searched by id"
                                  key :produces, ['application/json']
                                  key :tags, ['point']
                    Severity: Major
                    Found in app/controllers/api/v8/courses/users/points_controller.rb and 3 other locations - About 1 hr to fix
                    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/submissions/last_hour_controller.rb on lines 10..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 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

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

                            swagger_path '/api/v8/courses/{course_id}/points' do
                              operation :get do
                                key :description, "Returns the course's points in a json format. Course is searched by id"
                                key :produces, ['application/json']
                                key :tags, ['point']
                    Severity: Major
                    Found in app/controllers/api/v8/courses/points_controller.rb and 3 other locations - About 1 hr to fix
                    app/controllers/api/v8/core/organizations/courses_controller.rb on lines 10..24
                    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

                    Severity
                    Category
                    Status
                    Source
                    Language