ministryofjustice/Claim-for-Crown-Court-Defence

View on GitHub
app/validators/claim/base_claim_validator.rb

Summary

Maintainability
C
7 hrs
Test Coverage
A
97%

Class BaseClaimValidator has 53 methods (exceeds 24 allowed). Consider refactoring.
Open

  class BaseClaimValidator < BaseValidator
    def self.mandatory_fields
      %i[external_user_id creator amount_assessed evidence_checklist_ids earliest_representation_order_date]
    end

Severity: Major
Found in app/validators/claim/base_claim_validator.rb - About 6 hrs to fix

    File base_claim_validator.rb has 297 lines of code (exceeds 250 allowed). Consider refactoring.
    Wontfix

    module Claim
      class BaseClaimValidator < BaseValidator
        def self.mandatory_fields
          %i[external_user_id creator amount_assessed evidence_checklist_ids earliest_representation_order_date]
        end
    Severity: Minor
    Found in app/validators/claim/base_claim_validator.rb - About 3 hrs to fix

      Method validate_retrial_start_and_end has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate_retrial_start_and_end(start_attribute, end_attribute, inverse: false)
            return unless @record&.requires_retrial_dates?
            start_attribute, end_attribute = end_attribute, start_attribute if inverse
            # TODO: this condition is a temproary workaround for live data that existed prior to addition of retrial details
            validate_presence(start_attribute, :blank) if @record.editable?
      Severity: Minor
      Found in app/validators/claim/base_claim_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

      Method step_fields_for_validation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def step_fields_for_validation
            # NOTE: keeping existent validation for API purposes
            # The form validations just validate the fields for the current step
            return self.class.fields_for_steps[@record.form_step] || [] unless @record.from_api? || @record.form_step.nil?
            return self.class.fields_for_steps.values.flatten if !@record.from_api? && @record.form_step.nil?
      Severity: Minor
      Found in app/validators/claim/base_claim_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