zoer/xmlable

View on GitHub

Showing 11 of 11 total issues

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

      def export_node_children(node, opts)
        node.children.each do |child|
          next if child.is_a?(Nokogiri::XML::Attr)
          if child.is_a?(Nokogiri::XML::Element)
            next if opts.drop_empty_elements? && empty?(child)
Severity: Minor
Found in lib/xmlable/exports/xml_exporter.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 export_element_children has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def export_element_children(el, opts)
        object_handlers(el, opts).each_with_object({}) do |h, memo|
          obj = el[h.method_name]
          if h.is_a?(Handlers::Element)
            next if opts.drop_empty_elements? && empty?(obj)
Severity: Minor
Found in lib/xmlable/exports/json_exporter.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 node_attributes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def node_attributes(node, opts)
        return {} unless node.respond_to?(:attributes)
        attrs = node.attributes.values.select do |att|
          next if opts.drop_undescribed_attributes? && !described?(att)
          next if opts.drop_empty_attributes? && empty?(att)
Severity: Minor
Found in lib/xmlable/exports/xml_exporter.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_with has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def __initialize_with(value)
        if value.is_a?(Hash)
          value.each do |key, val|
            if respond_to?(:__overwrite_content) && __content_methods.include?(key.to_s)
              next __overwrite_content(val)
Severity: Minor
Found in lib/xmlable/mixins/instantiable.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 object_handlers has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def object_handlers(el, opts)
        handlers = []
        if el.respond_to?(:__attributes_handlers)
          el.__attributes_handlers.storage.each do |h|
            next if opts.drop_undescribed_attributes? && !described?(h)
Severity: Minor
Found in lib/xmlable/exports/json_exporter.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 export_element has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def export_element(el, opts)
        opts = node_merged_opts(el.__node, opts)
        handlers = object_handlers(el, opts)
        content = export_content(el, opts)
        return content if handlers.size == 0
Severity: Minor
Found in lib/xmlable/exports/json_exporter.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 export_element has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def export_element(node, opts)
        opts = node_merged_opts(node, opts)
        ns = node.namespace
        if ns && !node_ns_definition(node, ns.prefix)
          opts[:xml] = opts[:xml][ns.prefix] if ns.prefix
Severity: Minor
Found in lib/xmlable/exports/xml_exporter.rb - About 55 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

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

  module Attribute
    def self.included(base)
      base.send(:include, Mixins::Object)
      base.send(:include, Mixins::Castable)
      base.send(:include, Mixins::ValueStorage)
Severity: Minor
Found in lib/xmlable/attribute.rb and 1 other location - About 45 mins to fix
lib/xmlable/document.rb on lines 5..13

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 39.

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

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

  module Document
    def self.included(base)
      base.send(:include, Mixins::Object)
      base.send(:include, Mixins::Export)
      base.send(:include, Mixins::OptionsStorage)
Severity: Minor
Found in lib/xmlable/document.rb and 1 other location - About 45 mins to fix
lib/xmlable/attribute.rb on lines 5..13

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 39.

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

Method __nested has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def __nested(var)
          klass = superclass
          obj = nil
          loop do
            obj = klass.instance_variable_get(var)
Severity: Minor
Found in lib/xmlable/mixins/object.rb - About 25 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

Method __define_namespaces has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def __define_namespaces(handlers)
        handlers.each do |h|
          next if __node.namespace_scopes.find { |ns| ns.prefix == h.prefix }
          __node.add_namespace_definition(h.prefix ? h.prefix.to_s : nil, h.href)
        end
Severity: Minor
Found in lib/xmlable/mixins/namespace_definitions_storage.rb - About 25 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

Severity
Category
Status
Source
Language