znamenica/dneslov

View on GitHub
app/models/concerns/with_links.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method has too many lines. [50/15]
Open

   def self.included base
      base.class_eval do
         has_many :links, as: :info, dependent: :destroy

         scope :with_links, -> context do
Severity: Minor
Found in app/models/concerns/with_links.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 included is too high. [35.64/30]
Open

   def self.included base
      base.class_eval do
         has_many :links, as: :info, dependent: :destroy

         scope :with_links, -> context do
Severity: Minor
Found in app/models/concerns/with_links.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

Block has too many lines. [48/25]
Open

      base.class_eval do
         has_many :links, as: :info, dependent: :destroy

         scope :with_links, -> context do
            join_name = table.table_alias || table.name
Severity: Minor
Found in app/models/concerns/with_links.rb by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Method included has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

   def self.included base
      base.class_eval do
         has_many :links, as: :info, dependent: :destroy

         scope :with_links, -> context do
Severity: Minor
Found in app/models/concerns/with_links.rb - About 2 hrs to fix

    Block has too many lines. [35/25]
    Open

             scope :with_links, -> context do
                join_name = table.table_alias || table.name
                language_codes = [context[:locales]].flatten
                alphabeth_codes = Languageble.alphabeth_list_for(language_codes).flatten
                selector = self.select_values.dup
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

             scope :with_links, -> context do
                join_name = table.table_alias || table.name
                language_codes = [context[:locales]].flatten
                alphabeth_codes = Languageble.alphabeth_list_for(language_codes).flatten
                selector = self.select_values.dup
    Severity: Major
    Found in app/models/concerns/with_links.rb and 1 other location - About 1 hr to fix
    app/models/concerns/with_descriptions.rb on lines 12..51

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

    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

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

                if self.select_values.dup.empty?
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Redundant self detected.
    Open

                selector = self.select_values.dup
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

    Missing top-level module documentation comment.
    Open

    module WithLinks
    Severity: Minor
    Found in app/models/concerns/with_links.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

    Use the lambda method for multiline lambdas.
    Open

             scope :with_links, -> context do
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    Use the lambda method for multiline lambdas.
    Open

             scope :with_pure_links, -> do
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    Redundant self detected.
    Open

                if self.select_values.dup.empty?
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

    Do not use spaces between -> and opening brace in lambda literals
    Open

             scope :with_links, -> context do
                join_name = table.table_alias || table.name
                language_codes = [context[:locales]].flatten
                alphabeth_codes = Languageble.alphabeth_list_for(language_codes).flatten
                selector = self.select_values.dup
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    This cop checks for spaces between -> and opening parameter brace in lambda literals.

    Example: EnforcedStyle: requirenospace (default)

    # bad
      a = -> (x, y) { x + y }
    
      # good
      a = ->(x, y) { x + y }

    Example: EnforcedStyle: require_space

    # bad
      a = ->(x, y) { x + y }
    
      # good
      a = -> (x, y) { x + y }

    Wrap stabby lambda arguments with parentheses.
    Open

             scope :with_links, -> context do
    Severity: Minor
    Found in app/models/concerns/with_links.rb by rubocop

    Check for parentheses around stabby lambda arguments. There are two different styles. Defaults to require_parentheses.

    Example: EnforcedStyle: require_parentheses (default)

    # bad
    ->a,b,c { a + b + c }
    
    # good
    ->(a,b,c) { a + b + c}

    Example: EnforcedStyle: requirenoparentheses

    # bad
    ->(a,b,c) { a + b + c }
    
    # good
    ->a,b,c { a + b + c}

    There are no issues that match your filters.

    Category
    Status