TracksApp/tracks

View on GitHub
app/models/todo.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Mass assignment is not restricted using attr_accessible
Open

class Todo < ApplicationRecord
Severity: Critical
Found in app/models/todo.rb by brakeman

This warning comes up if a model does not limit what attributes can be set through mass assignment.

In particular, this check looks for attr_accessible inside model definitions. If it is not found, this warning will be issued.

Brakeman also warns on use of attr_protected - especially since it was found to be vulnerable to bypass. Warnings for mass assignment on models using attr_protected will be reported, but at a lower confidence level.

Note that disabling mass assignment globally will suppress these warnings.

Unprotected mass assignment
Open

      p = Project.create(value) if p.nil?
Severity: Minor
Found in app/models/todo.rb by brakeman

Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.

Example:

User.new(params[:user])

Unfortunately, if there is a user field called admin which controls administrator access, now any user can make themselves an administrator.

attr_accessible and attr_protected can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible is used, or mass assignment is completely disabled.

There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like

Unprotected mass assignment near line 61: User.new(params[:user])

The other warning is raised whenever a model is found which does not use attr_accessible. This produces generic warnings like

Mass assignment is not restricted using attr_accessible

with a list of affected models.

In Rails 3.1 and newer, mass assignment can easily be disabled:

config.active_record.whitelist_attributes = true

Unfortunately, it can also easily be bypassed:

User.new(params[:user], :without_protection => true)

Brakeman will warn on uses of without_protection.

Unprotected mass assignment
Open

      c = Context.create(value) if c.nil?
Severity: Minor
Found in app/models/todo.rb by brakeman

Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.

Example:

User.new(params[:user])

Unfortunately, if there is a user field called admin which controls administrator access, now any user can make themselves an administrator.

attr_accessible and attr_protected can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible is used, or mass assignment is completely disabled.

There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like

Unprotected mass assignment near line 61: User.new(params[:user])

The other warning is raised whenever a model is found which does not use attr_accessible. This produces generic warnings like

Mass assignment is not restricted using attr_accessible

with a list of affected models.

In Rails 3.1 and newer, mass assignment can easily be disabled:

config.active_record.whitelist_attributes = true

Unfortunately, it can also easily be bypassed:

User.new(params[:user], :without_protection => true)

Brakeman will warn on uses of without_protection.

Complex method Todo::import (95.0)
Open

  def self.import(filename, params, user)
    default_context = user.contexts.order('id').first
    return false if default_context.nil?

    count = 0
Severity: Minor
Found in app/models/todo.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Class Todo has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

class Todo < ApplicationRecord
  MAX_DESCRIPTION_LENGTH = 300
  MAX_NOTES_LENGTH = 60_000

  after_save :save_predecessors
Severity: Minor
Found in app/models/todo.rb - About 4 hrs to fix

    File todo.rb has 304 lines of code (exceeds 300 allowed). Consider refactoring.
    Open

    class Todo < ApplicationRecord
      MAX_DESCRIPTION_LENGTH = 300
      MAX_NOTES_LENGTH = 60_000
    
      after_save :save_predecessors
    Severity: Minor
    Found in app/models/todo.rb - About 2 hrs to fix

      Complex method Todo#save_predecessors (26.6)
      Open

        def save_predecessors
          unless @predecessor_array.nil? # Only save predecessors if they changed
            current_array = predecessors
            remove_array = current_array - @predecessor_array
            add_array = @predecessor_array - current_array
      Severity: Minor
      Found in app/models/todo.rb by flog

      Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

      You can read more about ABC metrics or the flog tool

      Todo#activate_pending_todos refers to 't' more than self (maybe move it to another class?)
      Open

          pending_todos = successors.select { |t| t.uncompleted_predecessors.empty? && !t.completed? }
          pending_todos.each { |t| t.activate! }
      Severity: Minor
      Found in app/models/todo.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      Todo#add_tags= refers to 'params' more than self (maybe move it to another class?)
      Open

          unless params[:tag].nil?
            tag_list = params[:tag].inject([]) { |list, value| list << value[:name] }
      Severity: Minor
      Found in app/models/todo.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      Todo#add_predecessor_list has approx 6 statements
      Open

        def add_predecessor_list(predecessor_list)
      Severity: Minor
      Found in app/models/todo.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.)

      Todo#save_predecessors has approx 10 statements
      Open

        def save_predecessors
      Severity: Minor
      Found in app/models/todo.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.)

      Todo has at least 34 methods
      Open

      class Todo < ApplicationRecord
      Severity: Minor
      Found in app/models/todo.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)

      Todo#self.import has approx 18 statements
      Open

        def self.import(filename, params, user)
      Severity: Minor
      Found in app/models/todo.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.)

      Todo#block_successors refers to 't' more than self (maybe move it to another class?)
      Open

          active_successors = successors.select { |t| t.active? || t.deferred? }
          active_successors.each { |t| t.block! }
      Severity: Minor
      Found in app/models/todo.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      Todo#predecessor_dependencies= refers to 'deps' more than self (maybe move it to another class?)
      Open

          return if deps.nil?
      
          # for multiple dependencies, value will be an array of id's, but for a single dependency,
          # value will be a string. In that case convert to array
          deps = [deps] unless deps.class == Array
      Severity: Minor
      Found in app/models/todo.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      Todo#self.import calls 'user.id' 3 times
      Open

            unless find_by_description_and_user_id row[params[:description].to_i], user.id
              todo = new
              todo.user = user
              todo.description = row[params[:description].to_i].truncate MAX_DESCRIPTION_LENGTH
              todo.context = Context.find_by_name_and_user_id(row[params[:context].to_i], user.id) || default_context
      Severity: Minor
      Found in app/models/todo.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.

      Todo#destroy calls 'successor.uncompleted_predecessors' 2 times
      Open

            successor.uncompleted_predecessors.delete(self)
            if successor.uncompleted_predecessors.empty?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#save_predecessors calls 'todo.nil?' 2 times
      Open

              unless todo.nil?
                @removed_predecessors << todo
                predecessors.delete(todo)
              end
            end
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:completed_at].to_i' 3 times
      Open

              todo.state = row[params[:completed_at].to_i].present? ? 'completed' : 'active'
              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
              todo.due = row[params[:due].to_i]
              todo.completed_at = row[params[:completed_at].to_i] if row[params[:completed_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:description].to_i' 2 times
      Open

            unless find_by_description_and_user_id row[params[:description].to_i], user.id
              todo = new
              todo.user = user
              todo.description = row[params[:description].to_i].truncate MAX_DESCRIPTION_LENGTH
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:created_at].to_i' 2 times
      Open

              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'row[params[:description].to_i]' 2 times
      Open

            unless find_by_description_and_user_id row[params[:description].to_i], user.id
              todo = new
              todo.user = user
              todo.description = row[params[:description].to_i].truncate MAX_DESCRIPTION_LENGTH
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'row[params[:notes].to_i]' 2 times
      Open

              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'row[params[:created_at].to_i]' 2 times
      Open

              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo has no descriptive comment
      Open

      class Todo < ApplicationRecord
      Severity: Minor
      Found in app/models/todo.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

      Todo#self.import calls 'params[:created_at]' 2 times
      Open

              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#add_tags= calls 'params[:tag]' 2 times
      Open

          unless params[:tag].nil?
            tag_list = params[:tag].inject([]) { |list, value| list << value[:name] }
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'row[params[:completed_at].to_i]' 3 times
      Open

              todo.state = row[params[:completed_at].to_i].present? ? 'completed' : 'active'
              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
              todo.due = row[params[:due].to_i]
              todo.completed_at = row[params[:completed_at].to_i] if row[params[:completed_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:description]' 2 times
      Open

            unless find_by_description_and_user_id row[params[:description].to_i], user.id
              todo = new
              todo.user = user
              todo.description = row[params[:description].to_i].truncate MAX_DESCRIPTION_LENGTH
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:project]' 2 times
      Open

              todo.project = Project.find_by_name_and_user_id(row[params[:project].to_i], user.id) if row[params[:project].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:completed_at]' 3 times
      Open

              todo.state = row[params[:completed_at].to_i].present? ? 'completed' : 'active'
              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
              todo.due = row[params[:due].to_i]
              todo.completed_at = row[params[:completed_at].to_i] if row[params[:completed_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:project].to_i' 2 times
      Open

              todo.project = Project.find_by_name_and_user_id(row[params[:project].to_i], user.id) if row[params[:project].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:notes]' 2 times
      Open

              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'params[:notes].to_i' 2 times
      Open

              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'row[params[:completed_at].to_i].present?' 2 times
      Open

              todo.state = row[params[:completed_at].to_i].present? ? 'completed' : 'active'
              todo.notes = row[params[:notes].to_i].truncate MAX_NOTES_LENGTH if row[params[:notes].to_i].present?
              todo.created_at = row[params[:created_at].to_i] if row[params[:created_at].to_i].present?
              todo.due = row[params[:due].to_i]
              todo.completed_at = row[params[:completed_at].to_i] if row[params[:completed_at].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#self.import calls 'row[params[:project].to_i]' 2 times
      Open

              todo.project = Project.find_by_name_and_user_id(row[params[:project].to_i], user.id) if row[params[:project].to_i].present?
      Severity: Minor
      Found in app/models/todo.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.

      Todo#has_project? performs a nil-check
      Open

          return ! (project_id.nil? || project.is_a?(NullProject))
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#add_predecessor_list performs a nil-check
      Open

            list << predecessor unless predecessor.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#project= performs a nil-check
      Open

          elsif !(value.nil? || value.is_a?(NullProject))
            p = Project.where(:name => value[:name]).first
            p = Project.create(value) if p.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#add_tags= performs a nil-check
      Open

          unless params[:tag].nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo has missing safe method 'toggle_completion!'
      Open

        def toggle_completion!
      Severity: Minor
      Found in app/models/todo.rb by reek

      A candidate method for the Missing Safe Method smell are methods whose names end with an exclamation mark.

      An exclamation mark in method names means (the explanation below is taken from here ):

      The ! in method names that end with ! means, “This method is dangerous”—or, more precisely, this method is the “dangerous” version of an otherwise equivalent method, with the same name minus the !. “Danger” is relative; the ! doesn’t mean anything at all unless the method name it’s in corresponds to a similar but bang-less method name. So, for example, gsub! is the dangerous version of gsub. exit! is the dangerous version of exit. flatten! is the dangerous version of flatten. And so forth.

      Such a method is called Missing Safe Method if and only if her non-bang version does not exist and this method is reported as a smell.

      Example

      Given

      class C
        def foo; end
        def foo!; end
        def bar!; end
      end

      Reek would report bar! as Missing Safe Method smell but not foo!.

      Reek reports this smell only in a class context, not in a module context in order to allow perfectly legit code like this:

      class Parent
        def foo; end
      end
      
      module Dangerous
        def foo!; end
      end
      
      class Son < Parent
        include Dangerous
      end
      
      class Daughter < Parent
      end

      In this example, Reek would not report the Missing Safe Method smell for the method foo of the Dangerous module.

      Todo#predecessor_dependencies= performs a nil-check
      Open

          return if deps.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#save_predecessors performs a nil-check
      Open

          unless @predecessor_array.nil? # Only save predecessors if they changed
            current_array = predecessors
            remove_array = current_array - @predecessor_array
            add_array = @predecessor_array - current_array
      
      
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo has missing safe method 'toggle_star!'
      Open

        def toggle_star!
      Severity: Minor
      Found in app/models/todo.rb by reek

      A candidate method for the Missing Safe Method smell are methods whose names end with an exclamation mark.

      An exclamation mark in method names means (the explanation below is taken from here ):

      The ! in method names that end with ! means, “This method is dangerous”—or, more precisely, this method is the “dangerous” version of an otherwise equivalent method, with the same name minus the !. “Danger” is relative; the ! doesn’t mean anything at all unless the method name it’s in corresponds to a similar but bang-less method name. So, for example, gsub! is the dangerous version of gsub. exit! is the dangerous version of exit. flatten! is the dangerous version of flatten. And so forth.

      Such a method is called Missing Safe Method if and only if her non-bang version does not exist and this method is reported as a smell.

      Example

      Given

      class C
        def foo; end
        def foo!; end
        def bar!; end
      end

      Reek would report bar! as Missing Safe Method smell but not foo!.

      Reek reports this smell only in a class context, not in a module context in order to allow perfectly legit code like this:

      class Parent
        def foo; end
      end
      
      module Dangerous
        def foo!; end
      end
      
      class Son < Parent
        include Dangerous
      end
      
      class Daughter < Parent
      end

      In this example, Reek would not report the Missing Safe Method smell for the method foo of the Dangerous module.

      Todo#context= performs a nil-check
      Open

            c = Context.create(value) if c.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#project performs a nil-check
      Open

          original_project.nil? ? Project.null_object : original_project
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#self.import performs a nil-check
      Open

          return false if default_context.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#add_predecessor performs a nil-check
      Open

          return if t.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      Todo#activate_pending_todos has the variable name 't'
      Open

          pending_todos = successors.select { |t| t.uncompleted_predecessors.empty? && !t.completed? }
          pending_todos.each { |t| t.activate! }
      Severity: Minor
      Found in app/models/todo.rb by reek

      An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      Todo#project= has the variable name 'p'
      Open

            p = Project.where(:name => value[:name]).first
            p = Project.create(value) if p.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      Todo#add_predecessor has the parameter name 't'
      Open

        def add_predecessor(t)
      Severity: Minor
      Found in app/models/todo.rb by reek

      An Uncommunicative Parameter Name is a parameter name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      Todo#block_successors has the variable name 't'
      Open

          active_successors = successors.select { |t| t.active? || t.deferred? }
          active_successors.each { |t| t.block! }
      Severity: Minor
      Found in app/models/todo.rb by reek

      An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      Todo#context= has the variable name 'c'
      Open

            c = Context.where(:name => value[:name]).first
            c = Context.create(value) if c.nil?
      Severity: Minor
      Found in app/models/todo.rb by reek

      An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      There are no issues that match your filters.

      Category
      Status