houston/houston-core

View on GitHub
lib/houston/boot/serializer.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Method has too many lines. [30/10]
Open

    def pack(object)
      case object
      when Array
        object.map { |item| pack(item) }
      when Hash
Severity: Minor
Found in lib/houston/boot/serializer.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for pack is too high. [26.17/15]
Open

    def pack(object)
      case object
      when Array
        object.map { |item| pack(item) }
      when Hash
Severity: Minor
Found in lib/houston/boot/serializer.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method pack has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def pack(object)
      case object
      when Array
        object.map { |item| pack(item) }
      when Hash
Severity: Minor
Found in lib/houston/boot/serializer.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

Cyclomatic complexity for pack is too high. [11/6]
Open

    def pack(object)
      case object
      when Array
        object.map { |item| pack(item) }
      when Hash
Severity: Minor
Found in lib/houston/boot/serializer.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method pack has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def pack(object)
      case object
      when Array
        object.map { |item| pack(item) }
      when Hash
Severity: Minor
Found in lib/houston/boot/serializer.rb - About 1 hr to fix

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

        def unpack(object)
          if object.is_a?(Array)
            object.map { |item| unpack(item) }
          elsif object.is_a?(Hash)
            object = object.each_with_object({}) { |(key, value), new_object| new_object[key] = unpack(value) }
    Severity: Minor
    Found in lib/houston/boot/serializer.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

    Line is too long. [101/80]
    Open

            raise ArgumentError, "#{string.inspect} is the wrong type; it should be a String or NilClass"
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Line is too long. [107/80]
    Open

            object = object.each_with_object({}) { |(key, value), new_object| new_object[key] = unpack(value) }
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

            serializer = object["^S"]
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Do not use semicolons to terminate expressions.
    Open

          pack(object); nil
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

    Example:

    # bad
    foo = 1; bar = 2;
    baz = 3;
    
    # good
    foo = 1
    bar = 2
    baz = 3

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

                raise UnserializableError, "Hash keys must be either strings or symbols"
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Line is too long. [84/80]
    Open

                raise UnserializableError, "Hash keys must be either strings or symbols"
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Extra empty line detected at class body end.
    Open

    
      end
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    This cops checks if empty lines around the bodies of classes match the configuration.

    Example: EnforcedStyle: empty_lines

    # good
    
    class Foo
    
      def bar
        # ...
      end
    
    end

    Example: EnforcedStyle: emptylinesexcept_namespace

    # good
    
    class Foo
      class Bar
    
        # ...
    
      end
    end

    Example: EnforcedStyle: emptylinesspecial

    # good
    class Foo
    
      def bar; end
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    class Foo
      def bar
        # ...
      end
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

              packed_object["^S"] = serializer.class.name if serializer.respond_to?(:unpack)
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Keep a blank line before and after private.
    Open

      private
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Access modifiers should be surrounded by blank lines.

    Example:

    # bad
    class Foo
      def bar; end
      private
      def baz; end
    end
    
    # good
    class Foo
      def bar; end
    
      private
    
      def baz; end
    end

    Missing top-level class documentation comment.
    Open

      class Serializer
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

    The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

    Example:

    # bad
    class Person
      # ...
    end
    
    # good
    # Description/Explanation of Person class
    class Person
      # ...
    end

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

    require "oj"
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    Indent access modifiers like private.
    Open

      private
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Modifiers should be indented as deep as method definitions, or as deep as the class/module keyword, depending on configuration.

    Example: EnforcedStyle: indent (default)

    # bad
    class Plumbus
    private
      def smooth; end
    end
    
    # good
    class Plumbus
      private
      def smooth; end
    end

    Example: EnforcedStyle: outdent

    # bad
    class Plumbus
      private
      def smooth; end
    end
    
    # good
    class Plumbus
    private
      def smooth; end
    end

    Surrounding space missing in default value assignment.
    Open

        def initialize(serializers=Houston.serializers)
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.

    Example:

    # bad
    def some_method(arg1=:default, arg2=nil, arg3=[])
      # do something...
    end
    
    # good
    def some_method(arg1 = :default, arg2 = nil, arg3 = [])
      # do something...
    end

    Line is too long. [88/80]
    Open

              packed_object["^S"] = serializer.class.name if serializer.respond_to?(:unpack)
    Severity: Minor
    Found in lib/houston/boot/serializer.rb by rubocop

    There are no issues that match your filters.

    Category
    Status