resource-watch/resource-watch-manager

View on GitHub

Showing 48 of 48 total issues

Method index has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    if params.include?('user.role') && @user&.dig('role').eql?('ADMIN')
      usersIdsByRole = UserService.usersByRole(params['user.role'], request.headers['x-api-key'])
      if (params.include?('user'))
        params['user'].concat usersIdsByRole if params['user'].kind_of?(Array)
Severity: Minor
Found in app/controllers/api/dashboards_controller.rb - About 4 hrs 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 get_order has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  def self.get_order(options = {})
    sort_string = ''
    if options['sort']
      process_sort_string(options['sort']).split(',').each do |sort|
        field_name = sort[0] == '-' ? sort[1..-1] : sort
Severity: Minor
Found in app/models/dashboard.rb - About 2 hrs 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 fetch_all has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def self.fetch_all(options = {})
    dashboards = Dashboard.all

    # Deprecated: Please use the same filter options without nesting them in the `filter` param
    if options[:filter]
Severity: Minor
Found in app/models/dashboard.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 index has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    if params.include?('user.role') && @user&.dig('role').eql?('ADMIN')
      usersIdsByRole = UserService.usersByRole(params['user.role'], request.headers['x-api-key'])
      if (params.include?('user'))
        params['user'].concat usersIdsByRole if params['user'].kind_of?(Array)
Severity: Minor
Found in app/controllers/api/dashboards_controller.rb - About 1 hr to fix

    Method log_request_to_cloud_watch has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def log_request_to_cloud_watch(validation_response, request)
        logger.debug 'Logging request to CloudWatch'
    
        log_query = request.query_parameters.except(:loggedUser)
    
    
    Severity: Minor
    Found in app/controllers/api_controller.rb - About 1 hr to fix

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

        def assign_content_image_url(contents, content, _base_url, is_grid = false, grid = nil)
          content_image = create_content_image(content)
      
          if content_image.present?
            if is_grid
      Severity: Major
      Found in app/models/topic.rb and 1 other location - About 1 hr to fix
      app/models/dashboard.rb on lines 163..175

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

      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

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

        def assign_content_image_url(contents, content, _base_url, is_grid = false, grid = nil)
          content_image = create_content_image(content)
      
          if content_image.present?
            if is_grid
      Severity: Major
      Found in app/models/dashboard.rb and 1 other location - About 1 hr to fix
      app/models/topic.rb on lines 137..149

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

      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 validate_request has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def validate_request(request)
          logger.debug 'Validating request'
      
          if request.headers['Authorization'].nil?
            logger.debug 'No authorization header found'
      Severity: Minor
      Found in app/controllers/api_controller.rb - About 1 hr to fix

        Method get_order has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Minor
        Found in app/models/static_page.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 fetch_all has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.fetch_all(options = {})
            topics = Topic.all
            if options[:filter]
              topics = topics.by_published(options[:filter][:published]) if options[:filter][:published]
              topics = topics.by_private(options[:filter][:private]) if options[:filter][:private]
        Severity: Minor
        Found in app/models/topic.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 validate_request has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def validate_request(request)
            logger.debug 'Validating request'
        
            if request.headers['Authorization'].nil?
              logger.debug 'No authorization header found'
        Severity: Minor
        Found in app/controllers/api_controller.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 get_order has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Minor
        Found in app/models/tool.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 get_order has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Minor
        Found in app/models/topic.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 get_order has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Minor
        Found in app/models/partner.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

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

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Major
        Found in app/models/partner.rb and 3 other locations - About 1 hr to fix
        app/models/static_page.rb on lines 55..67
        app/models/tool.rb on lines 38..50
        app/models/topic.rb on lines 60..72

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

        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 4 locations. Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Major
        Found in app/models/static_page.rb and 3 other locations - About 1 hr to fix
        app/models/partner.rb on lines 96..108
        app/models/tool.rb on lines 38..50
        app/models/topic.rb on lines 60..72

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

        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 4 locations. Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Major
        Found in app/models/topic.rb and 3 other locations - About 1 hr to fix
        app/models/partner.rb on lines 96..108
        app/models/static_page.rb on lines 55..67
        app/models/tool.rb on lines 38..50

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

        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 4 locations. Consider refactoring.
        Open

          def self.get_order(options = {})
            field = 'created_at'
            direction = 'ASC'
            if options['sort']
              f = options['sort'].split(',').first
        Severity: Major
        Found in app/models/tool.rb and 3 other locations - About 1 hr to fix
        app/models/partner.rb on lines 96..108
        app/models/static_page.rb on lines 55..67
        app/models/topic.rb on lines 60..72

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

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

          def manage_content(base_url)
            content_images.each(&:destroy)
        
            begin
              contents = JSON.parse(content)
        Severity: Minor
        Found in app/models/topic.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 manage_content has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def manage_content(base_url)
            content_images.each(&:destroy)
        
            begin
              contents = JSON.parse(content)
        Severity: Minor
        Found in app/models/dashboard.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

        Severity
        Category
        Status
        Source
        Language