TracksApp/tracks

View on GitHub
lib/tracks/attribute_handler.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Class AttributeHandler has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

  class AttributeHandler
    attr_reader :attributes

    def initialize(user, attributes)
      @user = user
Severity: Minor
Found in lib/tracks/attribute_handler.rb - About 2 hrs to fix

    Tracks::AttributeHandler has at least 21 methods
    Open

      class AttributeHandler
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by reek

    Too Many Methods is a special case of LargeClass.

    Example

    Given this configuration

    TooManyMethods:
      max_methods: 3

    and this code:

    class TooManyMethods
      def one; end
      def two; end
      def three; end
      def four; end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [1]:TooManyMethods has at least 4 methods (TooManyMethods)

    Tracks::AttributeHandler#parse_collection has approx 8 statements
    Open

        def parse_collection(object_type, relation)
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Tracks::AttributeHandler has no descriptive comment
    Open

      class AttributeHandler
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by reek

    Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

    Example

    Given

    class Dummy
      # Do things...
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [1]:Dummy has no descriptive comment (IrresponsibleModule)

    Fixing this is simple - just an explaining comment:

    # The Dummy class is responsible for ...
    class Dummy
      # Do things...
    end

    Tracks::AttributeHandler#parse_collection calls 'attribute_with_id_of(object_type)' 2 times
    Open

            object = attribute_with_id_of(object_type).present? ? relation.find(attribute_with_id_of(object_type)) : nil
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by reek

    Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

    Reek implements a check for Duplicate Method Call.

    Example

    Here's a very much simplified and contrived example. The following method will report a warning:

    def double_thing()
      @other.thing + @other.thing
    end

    One quick approach to silence Reek would be to refactor the code thus:

    def double_thing()
      thing = @other.thing
      thing + thing
    end

    A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

    class Other
      def double_thing()
        thing + thing
      end
    end

    The approach you take will depend on balancing other factors in your code.

    Tracks::AttributeHandler#find_or_create_by_name doesn't depend on instance state (maybe move it to another class?)
    Open

        def find_or_create_by_name(relation, name)
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by reek

    A Utility Function is any instance method that has no dependency on the state of the instance.

    Tracks::AttributeHandler#normalize doesn't depend on instance state (maybe move it to another class?)
    Open

        def normalize(attributes)
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by reek

    A Utility Function is any instance method that has no dependency on the state of the instance.

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :recurring_target, :daily_every_x_days, :monthly_day_of_week,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Redundant return detected. To return multiple values, use an array.
    Open

          return object, new_object_created
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :ends_on, :end_date, :number_of_occurrences, :occurrences_count, :target,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :recurring_period, :daily_selector, :monthly_selector, :yearly_selector,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :monthly_every_xth_day, :recurring_show_days_before,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :context, :project,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :weekday, :show_always, :context_name, :project_name, :tag_list,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Missing magic comment # frozen_string_literal: true.
    Open

    module Tracks
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    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 `<<` are
    # called on a string literal.
    # bad
    module Bar
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Bar
      # ...
    end

    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

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Redundant return detected. To return multiple values, use an array.
    Open

          return object, new_object_created
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :recurring_show_always, :weekly_every_x_week, :weekly_return_monday,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :monthly_every_x_day, :monthly_every_x_month2, :monthly_every_x_month,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :yearly_month_of_year2, :yearly_month_of_year,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Redundant use of Object#to_s in interpolation.
    Open

            @attributes["#{object_type.to_s}_id".to_sym] = object.id unless new_object_created
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    This cop checks for string conversion in string interpolation, which is redundant.

    Example:

    # bad
    
    "result is #{something.to_s}"

    Example:

    # good
    
    "result is #{something}"

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :every_other2, :every_other3, :every_day, :only_work_days, :every_count,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Indent the first parameter one step more than the start of the previous line.
    Open

          :context, :project,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    This cop checks the indentation of the first parameter in a method call. Parameters after the first one are checked by Style/AlignParameters, not by this cop.

    Example:

    # bad
    some_method(
    first_param,
    second_param)
    
    # good
    some_method(
      first_param,
    second_param)

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :weekly_return_thursday, :weekly_return_friday, :weekly_return_saturday, :weekly_return_sunday
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :context_id, :project_id, :description, :notes, :state, :start_from,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Use one level of indentation for parameters following the first line of a multi-line method call.
    Open

          :show_from_delta, :recurring_period, :recurrence_selector, :every_other1,
    Severity: Minor
    Found in lib/tracks/attribute_handler.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    There are no issues that match your filters.

    Category
    Status