3scale/apisonator

View on GitHub

Showing 65 of 65 total issues

Class Application has 44 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Application
      include Storable

      # list of attributes to be fetched from storage
      ATTRIBUTES = [:state, :plan_id, :plan_name, :redirect_url].freeze
Severity: Minor
Found in lib/3scale/backend/application.rb - About 6 hrs to fix

    Class Service has 40 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Service
          include Storable
    
          # list of attributes to be fetched from storage
          ATTRIBUTES = %i[state referrer_filters_required backend_version provider_key].freeze
    Severity: Minor
    Found in lib/3scale/backend/service.rb - About 5 hrs to fix

      Method create_granularity_class has 105 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def create_granularity_class(name)
                Class.new do
                  include Instance
      
                  @name = name
      Severity: Major
      Found in lib/3scale/backend/period/period.rb - About 4 hrs to fix

        Class Metric has 28 methods (exceeds 20 allowed). Consider refactoring.
        Open

            class Metric
              module KeyHelpers
                def key(service_id, id, attribute)
                  encode_key("metric/service_id:#{service_id}/id:#{id}/#{attribute}")
                end
        Severity: Minor
        Found in lib/3scale/backend/metric.rb - About 3 hrs to fix

          Method cfg_sentinels_handler has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
          Open

                    def cfg_sentinels_handler(options)
                      # get role attr and remove from options
                      # will only be validated and included when sentinels are valid
                      role = options.delete :role
                      sentinels = options.delete :sentinels
          Severity: Minor
          Found in lib/3scale/backend/storage_helpers.rb - About 3 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

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

                def to_compact_s
                  s = year * 10000 +  month * 100 + day
                  if sec != 0
                    s = s * 100000 + hour * 1000 + min * 10
                    MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
          Severity: Major
          Found in lib/3scale/backend/extensions/time.rb and 1 other location - About 2 hrs to fix
          bench/extensions/to_compact_s_bench.rb on lines 19..32

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

          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

              def new_to_compact_s
                s = year * 10000 +  month * 100 + day
                if sec != 0
                  s = s * 100000 + hour * 1000 + min * 10
                  MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
          Severity: Major
          Found in bench/extensions/to_compact_s_bench.rb and 1 other location - About 2 hrs to fix
          lib/3scale/backend/extensions/time.rb on lines 52..65

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

          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

          Class Status has 24 methods (exceeds 20 allowed). Consider refactoring.
          Open

                class Status
                  # This is the default field we respond with when using OAuth redirects
                  # We only use 'redirect_uri' if a request sent such a param. See #397.
                  REDIRECT_URI_FIELD = 'redirect_url'.freeze
                  private_constant :REDIRECT_URI_FIELD
          Severity: Minor
          Found in lib/3scale/backend/transactor/status.rb - About 2 hrs to fix

            Class Memoizer has 23 methods (exceeds 20 allowed). Consider refactoring.
            Open

                class Memoizer
                  EXPIRE = 60
                  PURGE = 60
                  MAX_ENTRIES = 10000
                  ACTIVE = true
            Severity: Minor
            Found in lib/3scale/backend/memoizer.rb - About 2 hrs to fix

              Class UsageReport has 22 methods (exceeds 20 allowed). Consider refactoring.
              Open

                      class UsageReport
                        attr_reader :type, :period
              
                        def initialize(status, usage_limit)
                          @status      = status
              Severity: Minor
              Found in lib/3scale/backend/transactor/usage_report.rb - About 2 hrs to fix

                Method reschedule_failed_jobs has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                Open

                        def reschedule_failed_jobs
                          # There might be several callers trying to requeue failed jobs at the
                          # same time. We need to use a lock to avoid rescheduling the same
                          # failed job more than once.
                          key = dist_lock.lock
                Severity: Minor
                Found in lib/3scale/backend/failed_jobs_scheduler.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 delete_stats_keys_with_val_0 has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                Open

                          def delete_stats_keys_with_val_0(redis_conn, log_deleted_keys)
                            cursor = 0
                
                            loop do
                              with_retries do
                Severity: Minor
                Found in lib/3scale/backend/stats/cleaner.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

                Class Listener has 21 methods (exceeds 20 allowed). Consider refactoring.
                Open

                    class Listener < Sinatra::Base
                      disable :logging
                      enable :raise_errors
                      disable :show_exceptions
                
                
                Severity: Minor
                Found in lib/3scale/backend/listener.rb - About 2 hrs to fix

                  File listener.rb has 255 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  require '3scale/backend/version'
                  require '3scale/backend/cors'
                  require '3scale/backend/csp'
                  require 'json'
                  
                  
                  Severity: Minor
                  Found in lib/3scale/backend/listener.rb - About 2 hrs to fix

                    File application.rb has 254 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    module ThreeScale
                      module Backend
                        class Application
                          include Storable
                    
                    
                    Severity: Minor
                    Found in lib/3scale/backend/application.rb - About 2 hrs to fix

                      Method normalize_non_empty_keys! has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def normalize_non_empty_keys!
                              AUTH_AUTHREP_COMMON_PARAMS.each do |p|
                                thisparam = params[p]
                                if !thisparam.nil?
                                  if thisparam.class != String
                      Severity: Minor
                      Found in lib/3scale/backend/listener.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 do_api_method has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def do_api_method(method_name)
                              halt 403 if params.nil?
                      
                              normalize_non_empty_keys!
                      
                      
                      Severity: Minor
                      Found in lib/3scale/backend/listener.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 to_compact_s has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def to_compact_s
                              s = year * 10000 +  month * 100 + day
                              if sec != 0
                                s = s * 100000 + hour * 1000 + min * 10
                                MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
                      Severity: Minor
                      Found in lib/3scale/backend/extensions/time.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 new_to_compact_s has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def new_to_compact_s
                            s = year * 10000 +  month * 100 + day
                            if sec != 0
                              s = s * 100000 + hour * 1000 + min * 10
                              MODS[sec] == 0 ? s + DIVS[sec] : s * 10 + sec
                      Severity: Minor
                      Found in bench/extensions/to_compact_s_bench.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 start has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def start(job_queue)
                              loop do
                                break if @shutdown
                      
                                jobs = fetch(wait: false, max: Worker::DEFAULT_MAX_CONCURRENT_JOBS)
                      Severity: Minor
                      Found in lib/3scale/backend/job_fetcher.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