ministryofjustice/Claim-for-Crown-Court-Defence

View on GitHub

Showing 50 of 66 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    def has_many_association_names_for_steps
      {
        case_details: [],
        defendants: [{ name: :defendants, options: { presence: true } }],
        offence_details: [],
app/validators/claim/litigator_claim_sub_model_validator.rb on lines 14..23

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 36.

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

Further Reading

Method equal_for_scheme_nine has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def equal_for_scheme_nine(other)
        return true unless other.fee_scheme_version == 9
        return false unless elected_case == other.elected_case
        return false unless elected_case || conclusion == other.conclusion

Severity: Minor
Found in app/models/claim/transfer_brain/data_item.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 test_editability has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def test_editability(model_instance)
          return unless fee_classes.include?(model_instance.class)
          model_instance.errors.add(:base, 'uneditable_state') unless model_instance.claim.editable?
        rescue StandardError
          true
Severity: Minor
Found in app/interfaces/api/helpers/api_helper.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 create_resource has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def create_resource(model_klass, params, api_response, arg_builder_proc)
          model_instance = validate_resource(model_klass, api_response, arg_builder_proc)

          if api_response.success?(200)
            created_or_updated_status = model_instance.new_record? ? 201 : 200
Severity: Minor
Found in app/interfaces/api/helpers/api_helper.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_mileage_rate_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_mileage_rate_id
    if @record.car_travel? || @record.bike_travel?
      validate_presence(:mileage_rate_id, :blank)
      if @record.mileage_rate_id.present? && (car_travel_missing_milage_rates || bike_travel_missing_milage_rates)
        add_error(:mileage_rate_id, :invalid)
Severity: Minor
Found in app/validators/expense_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_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

Avoid too many return statements within this method.
Open

      return Fee::MiscFeeType.agfs_scheme_10s if agfs_reform?
Severity: Major
Found in app/services/claims/fetch_eligible_misc_fee_types.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

          return Fee::MiscFeeType.agfs_scheme_12s if agfs_scheme_12?
    Severity: Major
    Found in app/services/claims/fetch_eligible_misc_fee_types.rb - About 30 mins to fix

      Function init has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        init: function (func, wait, immediate) {
          let timeout
          return function executedFunction () {
            const context = this
            const args = arguments
      Severity: Minor
      Found in app/webpack/javascripts/modules/Modules.Debounce.js - 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 all_values_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def all_values_for(key)
            each_with_object([]) do |(k, v), values|
              values << v if k.eql?(key)
              values.concat(v.select { |el| el.is_a?(Hash) }.flat_map { |el| el.all_values_for(key) }) if v.is_a? Array
              values.concat(v.all_values_for(key)) if v.is_a? Hash
      Severity: Minor
      Found in lib/extensions/hash_extension.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 assign_total_attrs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def assign_total_attrs
            # TODO: understand if this check is really needed
            # left it here mostly to ensure the new changes do
            # not impact anything API related
            return if from_api?
      Severity: Minor
      Found in app/models/claim/interim_claim.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 parse_options! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def parse_options!
          # The following personalisation is for the default provided template_id
          # If you use a different template_id, make sure to provide in the command line
          # the proper personalisation, encoded in JSON format. Example:
          # --personalisation "{\"name\":\"test\",\"visit_url\":\"https://test.com\"}"
      Severity: Minor
      Found in lib/email_notification_cli.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 notify_resource has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def notify_resource
            resource.reload
            if resource.active_for_authentication?
              set_flash_message :notice, :signed_up if is_flashing_format?
              sign_up(resource_name, resource)
      Severity: Minor
      Found in app/controllers/external_users/registrations_controller.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

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

        def sort_using(column, direction)
          raise 'Invalid column' unless sortable_by?(column)
          raise 'Invalid sort direction' unless %( asc desc ).include?(direction)
      
          if META_SORT_COLUMNS.include?(column)
      Severity: Minor
      Found in app/models/claims/sort.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 agfs_scheme_scope has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def agfs_scheme_scope
            return Fee::MiscFeeType.agfs_scheme_16s if agfs_scheme_16?
            return Fee::MiscFeeType.agfs_scheme_15s if agfs_scheme_15?
            return Fee::MiscFeeType.agfs_scheme_14s if agfs_scheme_14?
            return Fee::MiscFeeType.agfs_scheme_13s if agfs_scheme_13?
      Severity: Minor
      Found in app/services/claims/fetch_eligible_misc_fee_types.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 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

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

          def assign_total_attrs
            # TODO: understand if this check is really needed
            # left it here mostly to ensure the new changes do
            # not impact anything API related
            return if from_api?
      Severity: Minor
      Found in app/models/claim/litigator_claim.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 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 available_roles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def available_roles
          return %w[admin] if provider.nil?
      
          if provider.agfs? && provider.lgfs?
            %w[admin advocate litigator]
      Severity: Minor
      Found in app/models/external_user.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

      Severity
      Category
      Status
      Source
      Language