File ledger_item.rb
has 331 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "active_support/concern"
require "invoicing/ledger_item/render_html"
require "invoicing/ledger_item/render_ubl"
module Invoicing
Method account_summaries
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
def account_summaries(self_id, options={})
info = ledger_item_class_info
ext = Invoicing::ConnectionAdapterExt
debit_classes = select_matching_subclasses(:debit_when_sent_by_self, true, self.table_name, self.inheritance_column).map{|c| c.name}
Method sender_recipient_name_map
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def sender_recipient_name_map(*sender_recipient_ids)
sender_recipient_ids = sender_recipient_ids.flatten.map &:to_i
sender_recipient_to_ledger_item_ids = {}
result_map = {}
info = ledger_item_class_info
Method account_summary
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def account_summary(self_id, other_id=nil, options={})
info = ledger_item_class_info
self_id = self_id.to_i
other_id = [nil, ''].include?(other_id) ? nil : other_id.to_i
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method merge_conditions
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def merge_conditions(*conditions)
segments = []
conditions.each do |condition|
unless condition.blank?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method calculate_total_amount
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def calculate_total_amount
line_items = ledger_item_class_info.get(self, :line_items)
return if self.class.is_payment && line_items.empty?
net_total = tax_total = BigDecimal('0')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method debit?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def debit?(self_id)
sender_is_self = sent_by?(self_id)
recipient_is_self = received_by?(self_id)
raise ArgumentError, "self_id #{self_id.inspect} is neither sender nor recipient" unless sender_is_self || recipient_is_self
raise ArgumentError, "self_id #{self_id.inspect} is both sender and recipient" if sender_is_self && recipient_is_self
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
scope :sorted, lambda { |column|
table = ledger_item_class_info.method(quoted_table_name).to_s
column = ledger_item_class_info.method(column).to_s
if column_names.include?(column)
order("#{table}.#{connection.quote_column_name(column)}, #{table}.#{connection.quote_column_name(primary_key)}")
- 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 46.
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