Coursemology/coursemology2

View on GitHub
app/services/course/assessment/question/programming/java/java_package_service.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method generate_zip_file has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def generate_zip_file(data_files_to_keep, submission_files_to_keep, solution_files_to_keep)
    tmp = Tempfile.new(['package', '.zip'])
    autograde_build_path = File.join(File.expand_path(__dir__), 'java_build.xml').freeze
    autograde_pre_path = File.join(File.expand_path(__dir__), 'java_autograde_pre.java').freeze
    autograde_run_path = File.join(File.expand_path(__dir__), 'RunTests.java').freeze

Method generate_package has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def generate_package(old_attachment)
    return nil if @test_params.blank?

    @tmp_dir = Dir.mktmpdir
    @old_meta = old_attachment.present? ? extract_meta(old_attachment, nil) : nil

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

  def generate_zip_file(data_files_to_keep, submission_files_to_keep, solution_files_to_keep)
    tmp = Tempfile.new(['package', '.zip'])
    autograde_build_path = File.join(File.expand_path(__dir__), 'java_build.xml').freeze
    autograde_pre_path = File.join(File.expand_path(__dir__), 'java_autograde_pre.java').freeze
    autograde_run_path = File.join(File.expand_path(__dir__), 'RunTests.java').freeze

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

  def extract_from_package(package, file_type, new_filenames, files_to_delete)
    files_to_keep = []

    if @old_meta.present?
      package.unzip_file @tmp_dir

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

  def extract_autograded_meta(attachment)
    attachment.open(binmode: true) do |temporary_file|
      package = Course::Assessment::ProgrammingPackage.new(temporary_file)
      meta = package.meta_file
      @old_meta = meta.present? ? JSON.parse(meta) : nil

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

  def zip_test_files(test_type, zip) # rubocop:disable Metrics/AbcSize
    tests = @test_params[:test_cases]
    tests[test_type]&.each&.with_index(1) do |test, index|
      # String types should be displayed with quotes, other types will be converted to string
      # with the str method.

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

  def generate_standard_submission_solution_files(zip, submission_files_to_keep, solution_files_to_keep)
    zip.mkdir('submission')
    @test_params[:submission_files].try(:each) do |file|
      next if file.nil?

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

There are no issues that match your filters.

Category
Status