kaspernj/html_gen

View on GitHub
lib/html_gen/element.rb

Summary

Maintainability
D
1 day
Test Coverage

Method html has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

  def html(args = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
    level = args[:level] || 0

    if args.key?(:pretty)
      pretty = args[:pretty]
Severity: Minor
Found in lib/html_gen/element.rb - About 1 day 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

Method html has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def html(args = {}) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
    level = args[:level] || 0

    if args.key?(:pretty)
      pretty = args[:pretty]
Severity: Major
Found in lib/html_gen/element.rb - About 2 hrs to fix

    Method data_attributes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def data_attributes(data_hash, prev_key)
        html = ""
        data_hash.each do |key, value|
          key = key.to_s.tr("_", "-") if key.is_a?(Symbol)
    
    
    Severity: Minor
    Found in lib/html_gen/element.rb - About 1 hr 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

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

      def convert_style_to_css
        if !@attr[:style].to_s.strip.empty?
          style = @attr[:style]
        elsif !@attr["style"].to_s.strip.empty?
          style = @attr["style"]
    Severity: Minor
    Found in lib/html_gen/element.rb - About 1 hr 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

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

      def initialize(name, args = {})
        raise "'name' should be a string or a symbol but was a '#{name.class.name}'." if !name.is_a?(String) && !name.is_a?(Symbol)
        @name = name
    
        {attr: {}, data: {}, classes: [], str_html: "", str: "", css: {}, eles: [], nl: "\n", inden: "  "}.each do |arg, default_val|
    Severity: Minor
    Found in lib/html_gen/element.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

    There are no issues that match your filters.

    Category
    Status