unepwcmc/SAPI

View on GitHub
app/services/trade/filter.rb

Summary

Maintainability
D
2 days
Test Coverage

Method initialize_query has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
Open

  def initialize_query
    @query = Trade::Shipment.from("#{@shipments_view} AS trade_shipments")

    unless @taxon_concepts_ids.empty?
      cascading_ranks =
Severity: Minor
Found in app/services/trade/filter.rb - About 1 day 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 initialize_query has 93 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def initialize_query
    @query = Trade::Shipment.from("#{@shipments_view} AS trade_shipments")

    unless @taxon_concepts_ids.empty?
      cascading_ranks =
Severity: Major
Found in app/services/trade/filter.rb - About 3 hrs to fix

    Method initialize_internal_query has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def initialize_internal_query
        if @report_type == :raw
          # includes would override the select clause
          @query = @query.preload(:reported_taxon_concept)
        end
    Severity: Minor
    Found in app/services/trade/filter.rb - About 1 hr 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 eu_country_date_query has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def eu_country_date_query(start_year, end_year, type)
        eu_country_ids = instance_variable_get("@#{type}_eu_country_ids")
        country_query_arr = []
        eu_country_ids.each do |eu_country|
          # check for multiple entries for the same countries(UK might rejoin at some point)
    Severity: Minor
    Found in app/services/trade/filter.rb - About 1 hr 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 initialize_internal_query has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def initialize_internal_query
        if @report_type == :raw
          # includes would override the select clause
          @query = @query.preload(:reported_taxon_concept)
        end
    Severity: Minor
    Found in app/services/trade/filter.rb - About 1 hr to fix

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

          if !@purposes_ids.empty?
            local_field = "purpose_id"
            blank_query = @purpose_blank ? "OR purpose_id IS NULL" : ""
            @query = @query.where("#{local_field} IN (?) #{blank_query}", @purposes_ids)
          elsif @purpose_blank
      Severity: Minor
      Found in app/services/trade/filter.rb and 2 other locations - About 25 mins to fix
      app/services/trade/filter.rb on lines 92..98
      app/services/trade/filter.rb on lines 121..127

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

      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

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

          if !@units_ids.empty?
            local_field = "unit_id"
            blank_query = @unit_blank ? "OR unit_id IS NULL" : ""
            @query = @query.where("#{local_field} IN (?) #{blank_query}", @units_ids)
          elsif @unit_blank
      Severity: Minor
      Found in app/services/trade/filter.rb and 2 other locations - About 25 mins to fix
      app/services/trade/filter.rb on lines 100..106
      app/services/trade/filter.rb on lines 121..127

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

      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

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

          if !@countries_of_origin_ids.empty?
            local_field = "country_of_origin_id"
            blank_query = @country_of_origin_blank ? "OR country_of_origin_id IS NULL" : ""
            @query = @query.where("#{local_field} IN (?) #{blank_query}", @countries_of_origin_ids)
          elsif @country_of_origin_blank
      Severity: Minor
      Found in app/services/trade/filter.rb and 2 other locations - About 25 mins to fix
      app/services/trade/filter.rb on lines 92..98
      app/services/trade/filter.rb on lines 100..106

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

      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

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

            reported_taxon_concepts_conditions =
              reported_taxon_concepts.map do |tc|
                [:id, tc.id]
              end + reported_taxon_concepts.select do |tc|
                cascading_ranks.include?(tc.rank_name)
      Severity: Minor
      Found in app/services/trade/filter.rb and 1 other location - About 25 mins to fix
      app/services/trade/filter.rb on lines 45..51

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

      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

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

            taxon_concepts_conditions =
              taxon_concepts.map do |tc|
                [:id, tc.id]
              end + taxon_concepts.select do |tc|
                cascading_ranks.include?(tc.rank_name)
      Severity: Minor
      Found in app/services/trade/filter.rb and 1 other location - About 25 mins to fix
      app/services/trade/filter.rb on lines 61..67

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

      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

      There are no issues that match your filters.

      Category
      Status