zammad/zammad

View on GitHub
lib/websocket_server.rb

Summary

Maintainability
B
5 hrs
Test Coverage

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

  def self.send_to_client
    return if @clients.empty?

    # log 'debug', 'checking for data to send...'
    @clients.each do |client_id, client|
Severity: Minor
Found in lib/websocket_server.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 onmessage has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.onmessage(websocket, msg)
    client_id = websocket.object_id.to_s
    log 'info', "receiving #{msg.to_s.bytesize} bytes", client_id
    log 'debug', "received: #{msg}", client_id
    begin
Severity: Minor
Found in lib/websocket_server.rb - About 1 hr to fix

    Method run has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.run(options)
        @options = options
        @clients = {}
    
        # By default, we are only logging errors to STDOUT.
    Severity: Minor
    Found in lib/websocket_server.rb - About 1 hr to fix

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

        def self.log(level, data, client_id = '-')
          skip_log = true
      
          case level
          when 'error'
      Severity: Minor
      Found in lib/websocket_server.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 onmessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.onmessage(websocket, msg)
          client_id = websocket.object_id.to_s
          log 'info', "receiving #{msg.to_s.bytesize} bytes", client_id
          log 'debug', "received: #{msg}", client_id
          begin
      Severity: Minor
      Found in lib/websocket_server.rb - About 25 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_status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.log_status
          # websocket
          log 'info', "Status: websocket clients: #{@clients.size}"
          @clients.each_key do |client_id|
            log 'info', 'working...', client_id
      Severity: Minor
      Found in lib/websocket_server.rb - About 25 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

      There are no issues that match your filters.

      Category
      Status