ministryofjustice/Claim-for-Crown-Court-Defence

View on GitHub
app/validators/fee/base_fee_validator.rb

Summary

Maintainability
B
4 hrs
Test Coverage
A
98%

Class BaseFeeValidator has 28 methods (exceeds 24 allowed). Consider refactoring.
Open

  class BaseFeeValidator < BaseValidator
    def self.fields
      %i[
        amount
        warrant_issued_date
Severity: Minor
Found in app/validators/fee/base_fee_validator.rb - About 2 hrs to fix

    Method validate_fee_rate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_fee_rate(code = nil)
          if @record.quantity.positive? && @record.rate <= 0
            add_error(:rate, code ? :"#{code.downcase}_invalid" : :invalid)
          elsif @record.quantity <= 0 && @record.rate.positive?
            add_error(:quantity, code ? :"#{code.downcase}_invalid" : :invalid)
    Severity: Minor
    Found in app/validators/fee/base_fee_validator.rb - About 55 mins to fix

    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 validate_pcm_quantity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_pcm_quantity
          if @record.claim.supplementary? || @record.claim.case_type.try(:allow_pcmh_fee_type?)
            add_error(:quantity, :pcm_numericality) if @record.quantity > 3
          else
            add_error(:quantity, :pcm_not_applicable) unless @record.quantity.zero? || @record.quantity.blank?
    Severity: Minor
    Found in app/validators/fee/base_fee_validator.rb - About 35 mins to fix

    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 validate_amount has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_amount
          return if fee_code.nil?
          return if @record.calculated?
          add_error(:amount, :"#{fee_code.downcase}_invalid") if amount_outside_allowed_range?
    
    
    Severity: Minor
    Found in app/validators/fee/base_fee_validator.rb - About 25 mins to fix

    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

    There are no issues that match your filters.

    Category
    Status