armandofox/audience1st

View on GitHub
app/models/report.rb

Summary

Maintainability
B
6 hrs
Test Coverage
F
53%

Cyclomatic complexity for postprocess is too high. [13/6]
Open

  def postprocess
    # things we can do on the relation
    # we always seem to need Labels to include as part of result
    @relation = @relation.includes(:labels)
    @output_options.each_pair do |option,value|
Severity: Minor
Found in app/models/report.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 postprocess has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def postprocess
    # things we can do on the relation
    # we always seem to need Labels to include as part of result
    @relation = @relation.includes(:labels)
    @output_options.each_pair do |option,value|
Severity: Minor
Found in app/models/report.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 has too many lines. [32/30]
Open

  def postprocess
    # things we can do on the relation
    # we always seem to need Labels to include as part of result
    @relation = @relation.includes(:labels)
    @output_options.each_pair do |option,value|
Severity: Minor
Found in app/models/report.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.

Method postprocess has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def postprocess
    # things we can do on the relation
    # we always seem to need Labels to include as part of result
    @relation = @relation.includes(:labels)
    @output_options.each_pair do |option,value|
Severity: Minor
Found in app/models/report.rb - About 1 hr to fix

    Method add_data_rows has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def add_data_rows(csv)
        # grab the IDs of the whole set, then find in batches to avoid instantiating lots of objects
        order = self.output_options[:sort_by_zip] == '1' ?
                  "customers.zip, customers.last_name" :
                  "customers.last_name, customers.zip"
    Severity: Minor
    Found in app/models/report.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 add_data_rows has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def add_data_rows(csv)
        # grab the IDs of the whole set, then find in batches to avoid instantiating lots of objects
        order = self.output_options[:sort_by_zip] == '1' ?
                  "customers.zip, customers.last_name" :
                  "customers.last_name, customers.zip"
    Severity: Minor
    Found in app/models/report.rb - About 1 hr to fix

      Useless assignment to variable - header_row.
      Open

          csv << CSV::Row.new(@headers, @headers, header_row = true).to_s
      Severity: Minor
      Found in app/models/report.rb by rubocop

      This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

      assigned but unused variable - foo

      Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

      Example:

      # bad
      
      def some_method
        some_var = 1
        do_something
      end

      Example:

      # good
      
      def some_method
        some_var = 1
        do_something(some_var)
      end

      Useless assignment to variable - header_row.
      Open

                header_row = false
      Severity: Minor
      Found in app/models/report.rb by rubocop

      This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

      assigned but unused variable - foo

      Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

      Example:

      # bad
      
      def some_method
        some_var = 1
        do_something
      end

      Example:

      # good
      
      def some_method
        some_var = 1
        do_something(some_var)
      end

      Useless public access modifier.
      Open

        public
      Severity: Minor
      Found in app/models/report.rb by rubocop

      This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

      Example:

      class Foo
        public # this is redundant (default access is public)
      
        def method
        end
      
        private # this is not redundant (a method is defined)
        def method2
        end
      
        private # this is redundant (no following methods are defined)
      end

      Example:

      class Foo
        # The following is not redundant (conditionally defined methods are
        # considered as always defining a method)
        private
      
        if condition?
          def method
          end
        end
      
        protected # this is not redundant (method is defined)
      
        define_method(:method2) do
        end
      
        protected # this is redundant (repeated from previous modifier)
      
        [1,2,3].each do |i|
          define_method("foo#{i}") do
          end
        end
      
        # The following is redundant (methods defined on the class'
        # singleton class are not affected by the public modifier)
        public
      
        def self.method3
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   ContextCreatingMethods:
      #     - concerning
      require 'active_support/concern'
      class Foo
        concerning :Bar do
          def some_public_method
          end
      
          private
      
          def some_private_method
          end
        end
      
        # this is not redundant because `concerning` created its own context
        private
      
        def some_other_private_method
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   MethodCreatingMethods:
      #     - delegate
      require 'active_support/core_ext/module/delegation'
      class Foo
        # this is not redundant because `delegate` creates methods
        private
      
        delegate :method_a, to: :method_b
      end

      There are no issues that match your filters.

      Category
      Status