testmycode/tmc-server

View on GitHub

Showing 202 of 278 total issues

Method process_some_submissions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def process_some_submissions
    Submission.to_be_reprocessed.limit(2).each do |submission|
      Rails.logger.info "Attempting to process submission #{submission.id}"

      if submission.times_sent_to_sandbox < Submission.max_attempts_at_processing
Severity: Minor
Found in lib/submission_processor.rb - About 35 mins 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 student_row has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def self.student_row(ws, student_name)
    stripped = strip_leading_zeroes(student_name)
    return -1 if stripped.empty?

    (header_row + 1..ws.num_rows).each do |row|
Severity: Minor
Found in lib/gdocs_export.rb - About 35 mins 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

Avoid too many return statements within this method.
Open

            return
Severity: Major
Found in app/controllers/submissions_controller.rb - About 30 mins to fix

    Method force_utf8_violently has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def force_utf8_violently(str)
        if str.encoding == Encoding.find('UTF-8') && str.valid_encoding?
          str
        else
          str.dup.force_encoding('ISO-8859-1')
    Severity: Minor
    Found in app/helpers/bad_utf8_helper.rb - About 25 mins 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 get_course_and_exercise has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_course_and_exercise
          submission_id = params[:id] || params[:submission_id]
          if submission_id
            @submission = Submission.find(submission_id)
            authorize! :read, @submission
    Severity: Minor
    Found in app/controllers/submissions_controller.rb - About 25 mins 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_json_datatables has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def index_json_datatables
          submissions = @course.submissions
    
          unless current_user.administrator? || can?(:teach, @course)
            submissions = submissions.where(user_id: current_user.id)
    Severity: Minor
    Found in app/controllers/submissions_controller.rb - About 25 mins 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 parse_spec has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_spec(spec)
          # A spec is a proc that takes a user and returns a Time object or nil
          if DateAndTimeUtils.looks_like_date_or_time(spec)
            time = DateAndTimeUtils.to_time(spec, prefer_end_of_day: true)
            timefun = ->(_user) { time }
    Severity: Minor
    Found in app/models/deadline_spec.rb - About 25 mins 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 visible_to? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def visible_to?(user)
        user.administrator? ||
          user.teacher?(organization) ||
          user.assistant?(self) || (
          initial_refresh_ready? &&
    Severity: Minor
    Found in app/models/course.rb - About 25 mins 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 reject_common_login_mistakes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def reject_common_login_mistakes
          return if login.blank?
          errors.add(:login, 'may not be your email address. Keep in mind that your username is public to everyone.') if login.include?('@')
          errors.add(:login, 'may not be a number. Use the organizational identifier field for your student number.') if login.scan(/\D/).empty?
          errors.add(:email, 'may not end with "@ad.helsinki.fi". You cannot receive any emails with this address -- it\'s only used for your webmail login. Figure out what your real email address is and try again. It is usually of the form firstname.lastname@helsinki.fi but verify this first.') if email.end_with?('@ad.helsinki.fi')
    Severity: Minor
    Found in app/models/user.rb - About 25 mins 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 mark_as_read has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def mark_as_read(read)
          which = read ? 'read' : 'unread'
    
          fetch :review
          authorize! (read ? :mark_as_read : :mark_as_unread), @review
    Severity: Minor
    Found in app/controllers/reviews_controller.rb - About 25 mins 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 summary_hash has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def summary_hash(course, visible_exercises, sheets, only_for_user = nil)
          per_user_and_sheet = AwardedPoint.count_per_user_in_course_with_sheet(course, sheets, only_for_user, current_user.administrator?)
    
          user_totals = {}
          for username, per_sheet in per_user_and_sheet
    Severity: Minor
    Found in app/controllers/points_controller.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def show
        @sheetname = params[:id]
        @course = Course.find(params[:course_id])
        authorize! :see_points, @course
        return respond_unauthorized('Authentication required') if current_user.guest?
    Severity: Minor
    Found in app/controllers/points_controller.rb - About 25 mins 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_deadlines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def save_deadlines
        authorize! :manage_deadlines, @course
    
        groups = group_params
        groups.each do |name, deadlines|
    Severity: Minor
    Found in app/controllers/courses_controller.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def create
            authorize! :create, User
    
            @user = User.new
    
    
    Severity: Minor
    Found in app/controllers/api/v8/users_controller.rb - About 25 mins 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_unlocks_impl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.refresh_unlocks_impl(course, user, user_unlocks_by_exercise_name)
          course.exercises.enabled.each do |exercise|
            existing = user_unlocks_by_exercise_name[exercise.name]
            exists = !!existing
            may_exist = exercise.requires_unlock? && exercise.unlock_spec_obj.permits_unlock_for?(user)
    Severity: Minor
    Found in app/models/unlock.rb - About 25 mins 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 parse_date_or_time has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.parse_date_or_time(input)
        s = input.strip
    
        s = "#{Regexp.last_match(3)}-#{Regexp.last_match(2)}-#{Regexp.last_match(1)}#{Regexp.last_match(4)}" if s =~ /^(\d+)\.(\d+)\.(\d+)(.*)$/
    
    
    Severity: Minor
    Found in lib/date_and_time_utils.rb - About 25 mins 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 decode_test_output has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.decode_test_output(test_output)
          if test_output.blank?
            return 'Missing test output. Did you terminate your program with an exit() command? Also make sure your program did not run out of memory. For example excessive printing (thousands of lines) may cause this.'
          end
    
    
    Severity: Minor
    Found in lib/sandbox_results_saver.rb - About 25 mins 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 course_data_core_api has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def course_data_core_api(course)
        # UncomputedUnlock.resolve(course, @user)
        @unlocked_exercises = course.unlocks
                                    .where(user_id: @user.id)
                                    .where(['valid_after IS NULL OR valid_after < ?', Time.now])
    Severity: Minor
    Found in lib/course_info.rb - About 25 mins 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 handle_tmc_langs_output has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.handle_tmc_langs_output(submission, test_output)
          if test_output.key? 'logs'
            if test_output['logs'].key? 'stdout'
              submission.stdout = test_output['logs']['stdout']
            end
    Severity: Minor
    Found in lib/sandbox_results_saver.rb - About 25 mins 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 authenticate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.authenticate(notifications)
        notifications << 'gdocs_username undefined' && (return nil) unless
          TmcServer::Application.config.gdocs_username
        notifications << 'gdocs_password undefined' && (return nil) unless
          TmcServer::Application.config.gdocs_password
    Severity: Minor
    Found in lib/gdocs_export.rb - About 25 mins 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