distil/jserializer

View on GitHub
lib/jserializer/base.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Class has too many lines. [145/100]
Open

  class Base
    @_attributes = {}
    @_embed = :objects

    class << self
Severity: Minor
Found in lib/jserializer/base.rb by rubocop

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

Class Base has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Base
    @_attributes = {}
    @_embed = :objects

    class << self
Severity: Minor
Found in lib/jserializer/base.rb - About 2 hrs to fix

    Method _build_association has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def _build_association(name, type, key, serializer, embed, embed_key)
    Severity: Minor
    Found in lib/jserializer/base.rb - About 45 mins to fix

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

          def as_json(options = {})
            root = options.key?(:root) ? options[:root] : true
            hash = if root && root_name
                     { root_name => serializable_hash }
                   else
      Severity: Minor
      Found in lib/jserializer/base.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

      Avoid parameter lists longer than 5 parameters. [6/5]
      Open

            def _build_association(name, type, key, serializer, embed, embed_key)
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

      Rename has_many to many?.
      Open

            def has_many(name, serializer: nil, key: nil, embed: nil, embed_key: nil)
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop makes sure that predicates are named properly.

      Example:

      # bad
      def is_even?(value)
      end
      
      # good
      def even?(value)
      end
      
      # bad
      def has_value?
      end
      
      # good
      def value?
      end

      Use alias current_user scope instead of alias :current_user :scope.
      Open

          alias :current_user :scope
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

      Example: EnforcedStyle: prefer_alias (default)

      # bad
      alias_method :bar, :foo
      alias :bar :foo
      
      # good
      alias bar foo

      Example: EnforcedStyle: preferaliasmethod

      # bad
      alias :bar :foo
      alias bar foo
      
      # good
      alias_method :bar, :foo

      Rename has_one to one?.
      Open

            def has_one(name, serializer: nil, key: nil, embed: nil, embed_key: nil)
      Severity: Minor
      Found in lib/jserializer/base.rb by rubocop

      This cop makes sure that predicates are named properly.

      Example:

      # bad
      def is_even?(value)
      end
      
      # good
      def even?(value)
      end
      
      # bad
      def has_value?
      end
      
      # good
      def value?
      end

      Missing top-level class documentation comment.
      Open

        class Base
      Severity: Minor
      Found in lib/jserializer/base.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

      There are no issues that match your filters.

      Category
      Status