Coursemology/coursemology2

View on GitHub
app/services/course/assessment/question/programming/python/python_package_service.rb

Summary

Maintainability
B
4 hrs
Test Coverage

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

  def generate_zip_file(data_files_to_keep)
    tmp = Tempfile.new(['package', '.zip'])
    autograde_pre_path = get_file_path('python_autograde_pre.py')
    autograde_post_path = get_file_path('python_autograde_post.py')
    makefile_path = get_file_path('python_makefile')

Method extract_from_package has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def extract_from_package(package, new_data_filenames, data_files_to_delete)
    data_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 generate_package has a Cognitive Complexity of 7 (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 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
    # Print test class preamble
    test_class_name = "#{test_type}_tests_grader".camelize
    class_definition = <<~PYTHON
      class #{test_class_name}(unittest.TestCase):

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