neo4jrb/neo4j

View on GitHub
lib/active_graph/shared/type_converters.rb

Summary

Maintainability
B
5 hrs
Test Coverage

File type_converters.rb has 337 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'date'
require 'bigdecimal'
require 'bigdecimal/util'
require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/core_ext/string/conversions'
Severity: Minor
Found in lib/active_graph/shared/type_converters.rb - About 4 hrs to fix

Method convert_properties_to has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def convert_properties_to(obj, medium, properties)
      direction = medium == :ruby ? :to_ruby : :to_db
      properties.to_h.each_pair do |key, value|
        next if skip_conversion?(obj, key, value)

Severity: Minor
Found in lib/active_graph/shared/type_converters.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

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

      def to_other(direction, value, type)
        fail "Unknown direction given: #{direction}" unless direction == :to_ruby || direction == :to_db
        found_converter = converter_for(type)
        return value unless found_converter
        return value if direction == :to_db && formatted_for_db?(found_converter, value)
Severity: Minor
Found in lib/active_graph/shared/type_converters.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

Prefer Date or Time over DateTime. (https://github.com/bbatsov/ruby-style-guide#date--time)
Open

          DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec)

This cop checks for uses of DateTime that should be replaced by Date or Time.

Example:

# bad - uses `DateTime` for current time
DateTime.now

# good - uses `Time` for current time
Time.now

# bad - uses `DateTime` for modern date
DateTime.iso8601('2016-06-29')

# good - uses `Date` for modern date
Date.iso8601('2016-06-29')

# good - uses `DateTime` with start argument for historical date
DateTime.iso8601('1751-04-23', Date::ENGLAND)

Use underscores(_) as decimal mark and separate every 3 digits with them. (https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics)
Open

      NEO4J_SMALLEST_INT = -9223372036854775808

This cop checks for big numeric literals without _ between groups of digits in them.

Example:

# bad

1000000
1_00_000
1_0000

# good

1_000_000
1000

# good unless Strict is set

10_000_00 # typical representation of $10,000 in cents

Missing magic comment # frozen_string_literal: true.
Open

require 'date'

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Unused method argument - value. If it's necessary, use _ or _value as an argument name to indicate that it won't be used. You can also write as converted?(*) if you want the method to accept any arguments but don't care about them. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)
Open

        def converted?(value)

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
Open

        fail "Unknown direction given: #{direction}" unless direction == :to_ruby || direction == :to_db

This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

Example:

# bad
a = 'a'
foo if a == 'a' || a == 'b' || a == 'c'

# good
a = 'a'
foo if ['a', 'b', 'c'].include?(a)

Do not use empty case condition, instead use an if expression.
Open

      case

This cop checks for case statements with an empty condition.

Example:

# bad:
case
when x == 0
  puts 'x is 0'
when y == 0
  puts 'y is 0'
else
  puts 'neither is 0'
end

# good:
if x == 0
  puts 'x is 0'
elsif y == 0
  puts 'y is 0'
else
  puts 'neither is 0'
end

# good: (the case condition node is not empty)
case n
when 0
  puts 'zero'
when 1
  puts 'one'
else
  puts 'more'
end

Use underscores(_) as decimal mark and separate every 3 digits with them. (https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics)
Open

      NEO4J_LARGEST_INT = 9223372036854775807

This cop checks for big numeric literals without _ between groups of digits in them.

Example:

# bad

1000000
1_00_000
1_0000

# good

1_000_000
1000

# good unless Strict is set

10_000_00 # typical representation of $10,000 in cents

There are no issues that match your filters.

Category
Status