Showing 12 of 12 total issues
Class Invoice
has 36 methods (exceeds 20 allowed). Consider refactoring. Open
class Invoice < Sequel::Model
AlreadyFinalized = Class.new(StandardError)
def self.find_or_create_by_stripe_id(stripe_id)
transaction(isolation: :serializable,
Method finalize!
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def finalize!(stripe_event_id:, stripe_object:, charge:)
# If the document only has zero total lines, do not include it for bookkeeping.
# This happens when a customer subscribes when still in trial or no refund lines were set.
return if stripe_object.lines.map(&:amount).all?(&:zero?)
- 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 finalize!
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def finalize!(stripe_event_id:, stripe_object:, charge:)
# If the document only has zero total lines, do not include it for bookkeeping.
# This happens when a customer subscribes when still in trial or no refund lines were set.
return if stripe_object.lines.map(&:amount).all?(&:zero?)
Similar blocks of code found in 2 locations. Consider refactoring. Open
puts "migrating #{subscription.id} subscription for #{customer.id} (#{customer.email})"
puts "country: #{customer.metadata[:country_code]} vat: #{customer.metadata[:vat_registered]}"
puts "vat: #{vat_rate}"
if execute
- 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 43.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
puts "adding VAT to #{invoice.id} of #{customer.id} (#{customer.email})"
puts "country: #{customer.metadata[:country_code]} vat: #{customer.metadata[:vat_registered]}"
puts "vat: #{vat_rate}"
if execute
- 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 43.
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
Avoid deeply nested control flow statements. Open
if is_closed
puts 'reopening invoice'
invoice.closed = false
invoice.save
end
Avoid deeply nested control flow statements. Open
if is_closed
puts 'closing again'
invoice.closed = true
invoice.save
end
Method request
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.request(options)
begin
response = execute_request(options)
rescue SocketError => e
handle_restclient_error(e)
- 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 parse_attributes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def parse_attributes(data)
case data
when Hash
data.map do |(k,v)|
{
- 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 perform_for_single
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def perform_for_single(invoice)
# First load VIES data into the invoice.
vat_service.load_vies_data(invoice: invoice) if invoice.eu? && invoice.customer_vat_number
# Calculate total and vat amount in euro.
- 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 valid?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def valid?(vat_number:)
checksum = Valvat.new(vat_number).valid_checksum?
# Special case for the UK as after the brexit, the VIES service does not work anymore
# for the UK. We can however still checksum.
- 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 snapshot_document
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def snapshot_document(stripe_object)
props = {}
# In Stripe: total = subtotal - discount + tax
props[:total] = stripe_object.total.to_i
props[:subtotal] = stripe_object.subtotal.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"