jetrockets/attrio

View on GitHub

Showing 11 of 11 total issues

Method typecast has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def self.typecast(value, options = {})
        begin
          set = value.respond_to?(:split) ? value.split(options[:split]).to_set : Attrio::Helpers.to_a(value).to_set

          if options[:element].present?
Severity: Minor
Found in lib/attrio/types/set.rb - About 2 hrs 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 typecast has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def self.typecast(value, options = {})
        begin
          array = (!value.is_a?(::Array) && value.respond_to?(:split)) ? value.split(options[:split]): Attrio::Helpers.to_a(value).flatten
          if options[:element].present?

Severity: Minor
Found in lib/attrio/types/array.rb - About 2 hrs 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_typecasting_method has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

      def self.define_typecasting_method(klass, type, options)
        klass.send :define_method, options[:method_name] do |value|
          if !value.nil?
            value = if type.respond_to?(:typecast) && type.respond_to?(:typecasted?)
              type.typecasted?(value, options) ? value : type.typecast(*[value, options])
Severity: Minor
Found in lib/attrio/builders/writer_builder.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

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

          if options[:element].present?

            type = Attrio::AttributesParser.cast_type(self.element_type(options[:element]))
            options = self.element_options(options[:element])

Severity: Major
Found in lib/attrio/types/array.rb and 1 other location - About 1 hr to fix
lib/attrio/types/set.rb on lines 10..19

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

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

          if options[:element].present?
            type = Attrio::AttributesParser.cast_type(self.element_type(options[:element]))
            options = self.element_options(options[:element])

            set.map! do |item|
Severity: Major
Found in lib/attrio/types/set.rb and 1 other location - About 1 hr to fix
lib/attrio/types/array.rb on lines 9..19

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

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 typecast has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def self.typecast(value, options = {})
        true_values = options[:true] || options[:true_values] || ['yes', '1', 1, 'true']
        false_values = options[:false] || options[:false_values]

        if false_values.present?
Severity: Minor
Found in lib/attrio/types/boolean.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 cast_type has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def self.cast_type(constant)
      return constant if constant.is_a?(Class) && !!(constant < Attrio::Types::Base)

      string = constant.to_s
      string = string.camelize if (string =~ /\w_\w/ || string.chars.first.downcase == string.chars.first)
Severity: Minor
Found in lib/attrio/attributes_parser.rb - About 45 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 3 locations. Consider refactoring.
Open

  module Types
    class Time < Base
      def self.typecast(value, options = {})
        begin
          options[:format].present? ? ::Time.strptime(value.to_s, options[:format]) : ::Time.parse(value.to_s)
Severity: Major
Found in lib/attrio/types/time.rb and 2 other locations - About 45 mins to fix
lib/attrio/types/date.rb on lines 4..16
lib/attrio/types/date_time.rb on lines 4..16

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 3 locations. Consider refactoring.
Open

  module Types
    class DateTime < Base
      def self.typecast(value, options = {})
        begin
          options[:format].present? ? ::DateTime.strptime(value.to_s, options[:format]) : ::DateTime.parse(value.to_s)
Severity: Major
Found in lib/attrio/types/date_time.rb and 2 other locations - About 45 mins to fix
lib/attrio/types/date.rb on lines 4..16
lib/attrio/types/time.rb on lines 4..16

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 3 locations. Consider refactoring.
Open

  module Types
    class Date < Base
      def self.typecast(value, options = {})
        begin
          options[:format].present? ? ::Date.strptime(value.to_s, options[:format]) : ::Date.parse(value.to_s)
Severity: Major
Found in lib/attrio/types/date.rb and 2 other locations - About 45 mins to fix
lib/attrio/types/date_time.rb on lines 4..16
lib/attrio/types/time.rb on lines 4..16

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

Avoid too many return statements within this method.
Open

        return constant
Severity: Major
Found in lib/attrio/attributes_parser.rb - About 30 mins to fix
    Severity
    Category
    Status
    Source
    Language