3scale/porta

View on GitHub

Showing 5,269 of 5,606 total issues

Cinstance#push_webhook_key_updated calls 'User.current' 2 times
Open

    self.web_hook_event!({user: User.current, event: "key_updated"}) if User.current
Severity: Minor
Found in app/models/cinstance.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.

Contract#self.by_plan_type calls 'pricing_rules.id' 2 times
Open

                  plans.where { (cost_per_month == 0) & (setup_fee == 0) & (pricing_rules.id == nil) } # rubocop:disable Style/NumericPredicate,Style/NilComparison
                when 'paid'
                  plans.where { (cost_per_month != 0) | (setup_fee != 0) | (pricing_rules.id != nil) } # rubocop:disable Style/NumericPredicate,Style/NonNilCheck
Severity: Minor
Found in app/models/contract.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.

Metric#disable_for_plan calls 'plan.usage_limits' 2 times
Open

    used_periods   = plan.usage_limits.of_metric(self).pluck(:period).uniq.map(&:to_sym)
    unused_periods = UsageLimit::PERIODS - used_periods

    if unused_periods.present?
      plan.usage_limits
Severity: Minor
Found in app/models/metric.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 '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.

Backend::Status#initialize calls 'usage_set[usage_limit.period]' 2 times
Open

                usage_set[usage_limit.period] &&
                usage_set[usage_limit.period][usage_limit.metric_id] ||
Severity: Minor
Found in app/models/backend/status.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.

CMS::Section#add_remove_by_ids calls 'model_type.to_s.pluralize' 2 times
Open

    all = provider.send(model_type.to_s.pluralize)
    inside = self.send(model_type.to_s.pluralize)
Severity: Minor
Found in app/models/cms/section.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.

Configuration declares the class variable '@@current'
Open

    @@current = nil
    @@defaults       = nil
    @@allowed_values = nil
  end

Severity: Minor
Found in app/models/configuration.rb by reek

Class variables form part of the global runtime state, and as such make it easy for one part of the system to accidentally or inadvertently depend on another part of the system. So the system becomes more prone to problems where changing something over here breaks something over there. In particular, class variables can make it hard to set up tests (because the context of the test includes all global state).

For a detailed explanation, check out this article

Example

Given

class Dummy
  @@class_variable = :whatever
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Dummy declares the class variable @@class_variable (ClassVariable)

Getting rid of the smell

You can use class-instance variable to mitigate the problem (as also suggested in the linked article above):

class Dummy
  @class_variable = :whatever
end

Invoice#charge! calls 'provider_account.provider_can_use?(:new_notification_system)' 2 times
Open

        unless provider_account.provider_can_use?(:new_notification_system)
          InvoiceMessenger.unsuccessfully_charged_for_provider(self).deliver
        end

        event = Invoices::UnsuccessfullyChargedInvoiceProviderEvent.create(self)
Severity: Minor
Found in app/models/invoice.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.

PaymentTransaction::AmountWithCurrency#amount= manually dispatches method call
Open

      if value.respond_to?(:currency)
Severity: Minor
Found in app/models/payment_transaction.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#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.

Backend::Status#to_xml calls 'record.metric_id' 3 times
Open

            unless etern_ids.include?(record.metric_id)
              etern_ids << record.metric_id

              xml.usage(:metric => record.metric_name, :period => 'eternity') do |xml|
                etern_url = redis_url + "/metric:#{record.metric_id}/eternity"
Severity: Minor
Found in app/models/backend/status.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.

Configuration#delete calls 'self.class' 2 times
Open

    values[name] = self.class.defaults[name] if self.class.defaults.has_key?(name)
Severity: Minor
Found in app/models/configuration.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.

Contract#change_plan_internal calls 'self.plan' 2 times
Open

    return if self.plan == new_plan || new_plan.nil?
    raise 'change_plan_internal must be called with a block' unless block_given?

    transaction do

Severity: Minor
Found in app/models/contract.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.

Post#last_in_topic? calls 'topic.posts' 2 times
Open

    topic.posts.size == 1 && topic.posts.first == self
Severity: Minor
Found in app/models/post.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.

Backend::UsageAccumulator#calculate_cost_of calls 'values[:month]' 2 times
Open

        calculate_total_cost_of(values[:month] + usage) - calculate_total_cost_of(values[:month])

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.

SSOToken#account_is_provider_and_user_of_provider calls 'account.managed_users' 2 times
Open

        if account.managed_users.find_by_id(user_id).nil?
          errors.add :user_id, :invalid
        end
        return
      end
Severity: Minor
Found in app/models/sso_token.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.

Topic#check_for_moved_forum calls 'old.forum_id' 2 times
Open

    @old_forum_id = old.forum_id if old.forum_id != forum_id
Severity: Minor
Found in app/models/topic.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.

User::Roles#account_roles calls 'self.account' 2 times
Open

    if !self.account.nil? && self.account.provider?
Severity: Minor
Found in app/models/user/roles.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.

Configuration declares the class variable '@@defaults'
Open

    @@defaults ||= load_defaults
  end

  def self.reload
    @@current = nil
Severity: Minor
Found in app/models/configuration.rb by reek

Class variables form part of the global runtime state, and as such make it easy for one part of the system to accidentally or inadvertently depend on another part of the system. So the system becomes more prone to problems where changing something over here breaks something over there. In particular, class variables can make it hard to set up tests (because the context of the test includes all global state).

For a detailed explanation, check out this article

Example

Given

class Dummy
  @@class_variable = :whatever
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Dummy declares the class variable @@class_variable (ClassVariable)

Getting rid of the smell

You can use class-instance variable to mitigate the problem (as also suggested in the linked article above):

class Dummy
  @class_variable = :whatever
end
Severity
Category
Status
Source
Language