ManageIQ/manageiq

View on GitHub
app/models/miq_alert_set.rb

Summary

Maintainability
A
1 hr
Test Coverage
B
83%

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  ALERT_SET_MODES = {
    "ContainerGroup"      => ui_lookup(:model => "ContainerGroup"),
    "ContainerImage"      => ui_lookup(:model => "ContainerImage"),
    "ContainerNode"       => ui_lookup(:model => "ContainerNode"),
    "ContainerProject"    => ui_lookup(:model => "ContainerProject"),
Severity: Major
Found in app/models/miq_alert_set.rb and 1 other location - About 1 hr to fix
app/models/condition.rb on lines 21..30

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 48.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Prefer using YAML.safe_load over YAML.load.
Open

    input = YAML.load(fd)
Severity: Minor
Found in app/models/miq_alert_set.rb by rubocop

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