testmycode/tmc-server

View on GitHub

Showing 202 of 278 total issues

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

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

  def send_submission(submission, notify_url)
    exercise = submission.exercise

    raise 'Submission has no secret token' if submission.secret_token.blank?
    raise "Exercise #{submission.exercise_name} for submission gone. Cannot resubmit." if exercise.nil?
Severity: Minor
Found in app/models/remote_sandbox.rb - About 1 hr to fix

    Method update has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def update
        authorize! :teach, @organization
    
        print_setup_phases(3)
    
    
    Severity: Minor
    Found in app/controllers/setup/course_timings_controller.rb - About 1 hr to fix

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

        def show
          @exercise = Exercise.find(params[:id])
          @course = Course.lock('FOR SHARE').find(@exercise.course_id)
          @organization = @course.organization
          authorize! :read, @course
      Severity: Minor
      Found in app/controllers/exercises_controller.rb - About 1 hr to fix

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

          Method email_confirmation has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def email_confirmation(user, origin = nil, language = nil)
              @origin = origin
              @user = user
              token = user.verification_tokens.email.create!
              @url = confirm_email_url(@user.id, token.token, language: language)
          Severity: Minor
          Found in app/mailers/user_mailer.rb - About 1 hr to fix

            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

                  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

                    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

                      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

                      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
                          Severity
                          Category
                          Status
                          Source
                          Language