ManageIQ/manageiq-ui-classic

View on GitHub
app/services/widget_import_service.rb

Summary

Maintainability
A
35 mins
Test Coverage
A
100%

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

  def import_widgets(import_file_upload, widgets_to_import)
    number_imported_widgets = 0
    unless widgets_to_import.nil?
      widgets = YAML.load(import_file_upload.uploaded_content)

Severity: Minor
Found in app/services/widget_import_service.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

Prefer using YAML.safe_load over YAML.load.
Open

      widgets = YAML.load(import_file_upload.uploaded_content)

Checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

NOTE: Ruby 3.1+ (Psych 4) uses Psych.load as Psych.safe_load by default.

Safety:

The behavior of the code might change depending on what was in the YAML payload, since YAML.safe_load is more restrictive.

Example:

# bad
YAML.load("--- !ruby/object:Foo {}") # Psych 3 is unsafe by default

# good
YAML.safe_load("--- !ruby/object:Foo {}", [Foo])                    # Ruby 2.5  (Psych 3)
YAML.safe_load("--- !ruby/object:Foo {}", permitted_classes: [Foo]) # Ruby 3.0- (Psych 3)
YAML.load("--- !ruby/object:Foo {}", permitted_classes: [Foo])      # Ruby 3.1+ (Psych 4)
YAML.dump(foo)

There are no issues that match your filters.

Category
Status