QutBioacoustics/baw-workers

View on GitHub
lib/baw-workers/api_communicator.rb

Summary

Maintainability
D
1 day
Test Coverage

File api_communicator.rb has 275 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module BawWorkers
  class ApiCommunicator

    attr_accessor :logger

Severity: Minor
Found in lib/baw-workers/api_communicator.rb - About 2 hrs to fix

    Method send_request has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def send_request(description, method, host, port, endpoint, security_info = {auth_token: nil, cookies: nil}, body = nil)
    
          case method
            when :get
              request = Net::HTTP::Get.new(endpoint)
    Severity: Major
    Found in lib/baw-workers/api_communicator.rb - About 2 hrs to fix

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

          def send_request(description, method, host, port, endpoint, security_info = {auth_token: nil, cookies: nil}, body = nil)
      
            case method
              when :get
                request = Net::HTTP::Get.new(endpoint)
      Severity: Minor
      Found in lib/baw-workers/api_communicator.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 update_analysis_jobs_item_status has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def update_analysis_jobs_item_status(analysis_job_id, audio_recording_id, status, security_info)
            approved_statuses = [:working, :successful, :failed, :timed_out, :cancelled]
      
            raise "Cannot set status to `#{status}`" unless approved_statuses.include?(status)
      
      
      Severity: Minor
      Found in lib/baw-workers/api_communicator.rb - About 1 hr to fix

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

            def update_analysis_jobs_item_status(analysis_job_id, audio_recording_id, status, security_info)
              approved_statuses = [:working, :successful, :failed, :timed_out, :cancelled]
        
              raise "Cannot set status to `#{status}`" unless approved_statuses.include?(status)
        
        
        Severity: Minor
        Found in lib/baw-workers/api_communicator.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 request_login has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def request_login
              login_response = send_request('Login request', :post, host, port, endpoint_login, nil, {email: user, password: password})
        
              # get cookies
              # from http://stackoverflow.com/a/9320190/31567
        Severity: Minor
        Found in lib/baw-workers/api_communicator.rb - About 1 hr to fix

          Method send_request has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def send_request(description, method, host, port, endpoint, security_info = {auth_token: nil, cookies: nil}, body = nil)
          Severity: Major
          Found in lib/baw-workers/api_communicator.rb - About 50 mins to fix

            Method get_analysis_jobs_item_status has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_analysis_jobs_item_status(analysis_job_id, audio_recording_id, security_info)
                  endpoint = endpoint_analysis_jobs_item_update_status
                                 .gsub(':audio_recording_id', audio_recording_id.to_s)
                                 .gsub(':analysis_job_id', analysis_job_id.to_s)
            
            
            Severity: Minor
            Found in lib/baw-workers/api_communicator.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 update_audio_recording_details has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def update_audio_recording_details(description, file_to_process, audio_recording_id, update_hash, security_info)
            Severity: Minor
            Found in lib/baw-workers/api_communicator.rb - About 35 mins to fix

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

                  def create_new_audio_recording(file_to_process, project_id, site_id, audio_info_hash, security_info)
              Severity: Minor
              Found in lib/baw-workers/api_communicator.rb - About 35 mins to fix

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

                    def update_audio_recording_status(description, file_to_process, audio_recording_id, update_hash, security_info)
                Severity: Minor
                Found in lib/baw-workers/api_communicator.rb - About 35 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status