resource-watch/resource-watch-manager

View on GitHub

Showing 20 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 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

    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 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/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

        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/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 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 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 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

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

          def validate_user_and_application
            validation_response = validate_request(request)
            logger.debug 'validation response: ' + validation_response.to_json
        
            return false unless validation_response
        Severity: Minor
        Found in app/controllers/api_controller.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 ordering_params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def ordering_params(params)
            ordering = {}
            if params[:sort]
              sort_order = { '-' => :asc, '+' => :desc }
        
        
        Severity: Minor
        Found in app/controllers/concerns/orderable.rb - About 45 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 log_request_to_cloud_watch has a Cognitive Complexity of 8 (exceeds 5 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 45 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_content_image_url has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def assign_content_image_url(contents, content, _base_url, is_grid = false, grid = nil)
        Severity: Minor
        Found in app/models/topic.rb - About 35 mins to fix

          Method assign_content_image_url has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def assign_content_image_url(contents, content, _base_url, is_grid = false, grid = nil)
          Severity: Minor
          Found in app/models/dashboard.rb - About 35 mins to fix

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

              def self.fetch_all(options = {})
                partners = Partner.all
                if options[:filter]
                  partners = partners.by_published(options[:filter][:published]) if options[:filter][:published]
                  partners = partners.by_featured(options[:filter][:featured]) if options[:filter][:featured]
            Severity: Minor
            Found in app/models/partner.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

            Severity
            Category
            Status
            Source
            Language