codeclimate/codeclimate

View on GitHub
lib/cc/config/validation/fetch_validator.rb

Summary

Maintainability
A
35 mins
Test Coverage
A
95%

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

        def validate_path(path)
          if path.nil? || path.length.zero?
            errors << "fetch section's 'path' cannot be empty"
          else
            pathname = Pathname.new(path)
Severity: Minor
Found in lib/cc/config/validation/fetch_validator.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

Convert if-elsif to case-when.
Open

          if data.is_a?(String)
            validate_url(data)
          elsif data.is_a?(Hash)
            validate_fetch_hash
          else

Identifies places where if-elsif constructions can be replaced with case-when.

Safety:

This cop is unsafe. case statements use === for equality, so if the original conditional used a different equality operator, the behavior may be different.

Example:

# bad
if status == :active
  perform_action
elsif status == :inactive || status == :hibernating
  check_timeout
else
  final_action
end

# good
case status
when :active
  perform_action
when :inactive, :hibernating
  check_timeout
else
  final_action
end

There are no issues that match your filters.

Category
Status