Class Proposal
has 30 methods (exceeds 20 allowed). Consider refactoring. Open
class Proposal < ActiveRecord::Base
include Rails.application.routes.url_helpers
include Flaggable
include Taggable
include Conflictable
Identical blocks of code found in 2 locations. Consider refactoring. Open
def self.search_by_code(terms)
matched_code = match_code(terms)
results = where(id: matched_code[1]) if matched_code
return results if results.present? && results.first.code == terms
end
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 26.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Line is too long. [106/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) }
- Exclude checks
Line is too long. [105/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) }
- Exclude checks
Line is too long. [132/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago) }
- Exclude checks
%w
-literals should be delimited by [
and ]
. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces) Open
orders = %w{hot_score confidence_score created_at relevance archival_date}
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Line is too long. [128/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) }
- Exclude checks
Line is too long. [120/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
validates :responsible_name, length: { in: 6..Proposal.responsible_name_max_length }, unless: :skip_user_verification?
- Exclude checks
%w
-literals should be delimited by [
and ]
. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces) Open
RETIRE_OPTIONS = %w(duplicated started unfeasible done other)
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Line is too long. [118/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
orders << "recommendations" if Setting['feature.user.recommendations_on_proposals'] && user&.recommended_proposals
- Exclude checks
Line is too long. [131/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
scope :not_archived, -> { where("proposals.created_at > ?", Setting["months_to_archive_proposals"].to_i.months.ago) }
- Exclude checks