3scale/porta

View on GitHub
app/models/plan.rb

Summary

Maintainability
C
1 day
Test Coverage

attr_accessible is recommended over attr_protected
Open

  attr_protected :issuer_id, :original_id, :type, :issuer_type, :tenant_id, :audit_ids, :state
Severity: Minor
Found in app/models/plan.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.

Class Plan has 51 methods (exceeds 20 allowed). Consider refactoring.
Open

class Plan < ApplicationRecord
  include Searchable
  class PeriodRangeCalculationError < StandardError; end
  include Symbolize

Severity: Major
Found in app/models/plan.rb - About 7 hrs to fix

    File plan.rb has 317 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Plan < ApplicationRecord
      include Searchable
      class PeriodRangeCalculationError < StandardError; end
      include Symbolize
    
    
    Severity: Minor
    Found in app/models/plan.rb - About 3 hrs to fix

      Plan#create_contract_with refers to 'params' more than self (maybe move it to another class?)
      Open

          contract.application_id = params["application_id"] if params["application_id"]
          contract.user_key = params["user_key"] if params["user_key"]
      Severity: Minor
      Found in app/models/plan.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.

      Plan#xml_builder contains iterators nested 2 deep
      Open

            extra_nodes.each do |key,value|
      Severity: Minor
      Found in app/models/plan.rb by reek

      A Nested Iterator occurs when a block contains another block.

      Example

      Given

      class Duck
        class << self
          def duck_names
            %i!tick trick track!.each do |surname|
              %i!duck!.each do |last_name|
                puts "full name is #{surname} #{last_name}"
              end
            end
          end
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

      Plan#create_contract_with! refers to 'opts' more than self (maybe move it to another class?)
      Open

          new_contract.application_id = opts["application_id"] if opts["application_id"]
          new_contract.user_key = opts["user_key"] if opts["user_key"]
      Severity: Minor
      Found in app/models/plan.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.

      Plan#create_contract_with refers to 'contract' more than self (maybe move it to another class?)
      Open

          contract.application_id = params["application_id"] if params["application_id"]
          contract.user_key = params["user_key"] if params["user_key"]
          if buyer.new_record?
            # only build contract - it will be saved with account
            buyer.contracts << contract
      Severity: Minor
      Found in app/models/plan.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.

      Plan#create_contract_with has approx 9 statements
      Open

        def create_contract_with(buyer, opts = nil)
      Severity: Minor
      Found in app/models/plan.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.)

      Plan#copy refers to 'custom' more than self (maybe move it to another class?)
      Open

          custom.name = attrs[:name] || "#{custom.name} (copy)"
          custom.system_name = attrs[:system_name] || generate_copy_system_name
          custom.position = nil
          custom.contracts_count = custom.contracts.count
      
      
      Severity: Minor
      Found in app/models/plan.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.

      Plan#copy has approx 9 statements
      Open

        def copy(attrs = {})
      Severity: Minor
      Found in app/models/plan.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.)

      Plan has at least 48 methods
      Open

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

      Plan#create_contract_with is controlled by argument 'opts'
      Open

          params = opts || {}
      Severity: Minor
      Found in app/models/plan.rb by reek

      Control Parameter is a special case of Control Couple

      Example

      A simple example would be the "quoted" parameter in the following method:

      def write(quoted)
        if quoted
          write_quoted @value
        else
          write_unquoted @value
        end
      end

      Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

      Plan#create_contract_with! refers to 'new_contract' more than self (maybe move it to another class?)
      Open

          new_contract.application_id = opts["application_id"] if opts["application_id"]
          new_contract.user_key = opts["user_key"] if opts["user_key"]
          new_contract.user_account_id = buyer.id # this attribute is now protected
          new_contract.save!
      Severity: Minor
      Found in app/models/plan.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.

      Plan#xml_builder has approx 14 statements
      Open

        def xml_builder(options, attrs = {}, extra_nodes = {})
      Severity: Minor
      Found in app/models/plan.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.)

      Plan#create_contract_with calls 'params["user_key"]' 2 times
      Open

          contract.user_key = params["user_key"] if params["user_key"]
      Severity: Minor
      Found in app/models/plan.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.

      Plan#create_contract_with! calls 'opts["application_id"]' 2 times
      Open

          new_contract.application_id = opts["application_id"] if opts["application_id"]
      Severity: Minor
      Found in app/models/plan.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.

      Plan#currency_cache_key manually dispatches method call
      Open

          provider_account.try!(:id) if respond_to?(:provider_account)
      Severity: Minor
      Found in app/models/plan.rb by reek

      Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

      Example

      class MyManualDispatcher
        attr_reader :foo
      
        def initialize(foo)
          @foo = foo
        end
      
        def call
          foo.bar if foo.respond_to?(:bar)
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

      Plan#create_contract_with calls 'params["application_id"]' 2 times
      Open

          contract.application_id = params["application_id"] if params["application_id"]
      Severity: Minor
      Found in app/models/plan.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.

      Plan#create_contract_with! calls 'opts["user_key"]' 2 times
      Open

          new_contract.user_key = opts["user_key"] if opts["user_key"]
      Severity: Minor
      Found in app/models/plan.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.

      Plan#self.issued_by calls 'ids.blank?' 2 times
      Open

          when (issuer == :all || issuer.blank?) && ids.blank?
            where({})
          when issuer.respond_to?(:to_model) && ids.blank?
      Severity: Minor
      Found in app/models/plan.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.

      Plan#cost_for_period calls 'period.begin' 5 times
      Open

          same_month_period = (period.begin.month == period.end.month) && (period.begin.year == period.end.year)
          raise PeriodRangeCalculationError, 'Beginning and end of the period must both be in the same month' unless same_month_period
      
          # our ranges are actually correct but for arithmetic purposes we do want the + 1 (length of the range/month)
          month_part = (BigDecimal((period.end.to_i + 1).to_s) - BigDecimal(period.begin.to_i.to_s)) /
      Severity: Minor
      Found in app/models/plan.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.

      Plan assumes too much for instance variable '@cached_features'
      Open

      class Plan < ApplicationRecord
      Severity: Minor
      Found in app/models/plan.rb by reek

      Classes should not assume that instance variables are set or present outside of the current class definition.

      Good:

      class Foo
        def initialize
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Good as well:

      class Foo
        def foo?
          bar == :foo
        end
      
        def bar
          @bar ||= :foo
        end
      end

      Bad:

      class Foo
        def go_foo!
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Example

      Running Reek on:

      class Dummy
        def test
          @ivar
        end
      end

      would report:

      [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

      Note that this example would trigger this smell warning as well:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          @omg
        end
      end

      The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

      class Parent
        attr_reader :omg
      
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

      If you don't want to expose those methods as public API just make them private like this:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      
        private
        attr_reader :omg
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Current Support in Reek

      An instance variable must:

      • be set in the constructor
      • or be accessed through a method with lazy initialization / memoization.

      If not, Instance Variable Assumption will be reported.

      Plan#self.issued_by manually dispatches method call
      Open

          when issuer.respond_to?(:to_model) && ids.blank?
      Severity: Minor
      Found in app/models/plan.rb by reek

      Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

      Example

      class MyManualDispatcher
        attr_reader :foo
      
        def initialize(foo)
          @foo = foo
        end
      
        def call
          foo.bar if foo.respond_to?(:bar)
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

      Plan#copy calls 'attrs[:original]' 2 times
      Open

          custom.original = attrs[:original] unless attrs[:original].nil?
      Severity: Minor
      Found in app/models/plan.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.

      Plan#cost_for_period calls 'period.end' 3 times
      Open

          same_month_period = (period.begin.month == period.end.month) && (period.begin.year == period.end.year)
          raise PeriodRangeCalculationError, 'Beginning and end of the period must both be in the same month' unless same_month_period
      
          # our ranges are actually correct but for arithmetic purposes we do want the + 1 (length of the range/month)
          month_part = (BigDecimal((period.end.to_i + 1).to_s) - BigDecimal(period.begin.to_i.to_s)) /
      Severity: Minor
      Found in app/models/plan.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.

      Plan#copy performs a nil-check
      Open

          custom.original = attrs[:original] unless attrs[:original].nil?
      Severity: Minor
      Found in app/models/plan.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)

      Plan#customized? performs a nil-check
      Open

          !original.nil?
      Severity: Minor
      Found in app/models/plan.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)

      Plan has missing safe method 'enable_feature!'
      Open

        def enable_feature!(name)
      Severity: Minor
      Found in app/models/plan.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.

      Plan has missing safe method 'disable_feature!'
      Open

        def disable_feature!(name)
      Severity: Minor
      Found in app/models/plan.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.

      Plan#randomized doesn't depend on instance state (maybe move it to another class?)
      Open

        def randomized
      Severity: Minor
      Found in app/models/plan.rb by reek

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

      Plan#without_auditing_for_associations doesn't depend on instance state (maybe move it to another class?)
      Open

        def without_auditing_for_associations
      Severity: Minor
      Found in app/models/plan.rb by reek

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

      Plan#can_be_destroyed? has the variable name 'c'
      Open

          elsif customizations.any? { |c| c.contracts.exists? }
      Severity: Minor
      Found in app/models/plan.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