nadoka/nadoka

View on GitHub
ndk/server.rb

Summary

Maintainability
F
1 wk
Test Coverage

File server.rb has 644 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rice/irc'
require 'ndk/error'
require 'ndk/config'
require 'ndk/server_state'
require 'ndk/client'
Severity: Major
Found in ndk/server.rb - About 1 day to fix

    Method start_clients_thread has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        def start_clients_thread
          return unless @config.client_server_port
          @clients_thread = Thread.new{
            begin
              @cserver = TCPServer.new(@config.client_server_host,
    Severity: Minor
    Found in ndk/server.rb - About 6 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 server_main_proc has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def server_main_proc
          ## login
    
          # send passwd
          if @server_passwd
    Severity: Minor
    Found in ndk/server.rb - About 5 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 server_main_proc has 114 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def server_main_proc
          ## login
    
          # send passwd
          if @server_passwd
    Severity: Major
    Found in ndk/server.rb - About 4 hrs to fix

      Method start has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          def start
            start_server_thread
            start_clients_thread
            timer_thread = Thread.new{
              begin
      Severity: Minor
      Found in ndk/server.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

      Class NDK_Server has 31 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class NDK_Server
          TimerIntervalSec = 60
          MAX_PONG_FAIL    = 5
          
          def initialize rc
      Severity: Minor
      Found in ndk/server.rb - About 3 hrs to fix

        Method start_server_thread has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

            def start_server_thread
              @server_thread = Thread.new{
                begin
                  @server = make_server()
                  @logger.slog "Server connection to #{@server.server}:#{@server.port}."
        Severity: Minor
        Found in ndk/server.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

        Method recv_from_server has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            def recv_from_server
              while q = @rq.pop
                
                # Event
                if q.kind_of? Array
        Severity: Minor
        Found in ndk/server.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 send_to_bot has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def send_to_bot msg, *arg
        
              selector = 'on_' +
                if msg.respond_to? :command
                  if /^\d+$/ =~ msg.command
        Severity: Minor
        Found in ndk/server.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 start_clients_thread has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def start_clients_thread
              return unless @config.client_server_port
              @clients_thread = Thread.new{
                begin
                  @cserver = TCPServer.new(@config.client_server_host,
        Severity: Minor
        Found in ndk/server.rb - About 1 hr to fix

          Method start has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def start
                start_server_thread
                start_clients_thread
                timer_thread = Thread.new{
                  begin
          Severity: Minor
          Found in ndk/server.rb - About 1 hr to fix

            Method send_to_bot has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def send_to_bot msg, *arg
            
                  selector = 'on_' +
                    if msg.respond_to? :command
                      if /^\d+$/ =~ msg.command
            Severity: Minor
            Found in ndk/server.rb - About 1 hr to fix

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

                  def enter_away
                    return if @exitting || !@connected
                    
                    send_to_server Cmd.away(@config.away_message) if @config.away_message
              
              
              Severity: Minor
              Found in ndk/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 filter_message has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def filter_message filter, msg
                    return msg if filter.nil? || filter.empty?
                    
                    begin
                      if filter.respond_to? :each
              Severity: Minor
              Found in ndk/server.rb - About 1 hr to fix

                Method start_server_thread has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def start_server_thread
                      @server_thread = Thread.new{
                        begin
                          @server = make_server()
                          @logger.slog "Server connection to #{@server.server}:#{@server.port}."
                Severity: Minor
                Found in ndk/server.rb - About 1 hr to fix

                  Method exec_event has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def exec_event q
                        # special event
                        case q[0]
                        when :reload_config
                          # q[1] must be client object
                  Severity: Minor
                  Found in ndk/server.rb - About 1 hr to fix

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

                        def recv_from_server
                          while q = @rq.pop
                            
                            # Event
                            if q.kind_of? Array
                    Severity: Minor
                    Found in ndk/server.rb - About 1 hr to fix

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

                          def make_server
                            host, port, @server_passwd, ssl_params = next_server_info
                            server = ::RICE::Connection.new(host, port, "\r\n", ssl_params)
                            server.regist{|rq, wq|
                              Thread.stop
                      Severity: Minor
                      Found in ndk/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

                      Avoid deeply nested control flow statements.
                      Open

                                      if negate
                                        @isupport.delete(key)
                                      else
                                        @isupport[key] = value || true
                                      end
                      Severity: Major
                      Found in ndk/server.rb - About 45 mins to fix

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

                            def exec_event q
                              # special event
                              case q[0]
                              when :reload_config
                                # q[1] must be client object
                        Severity: Minor
                        Found in ndk/server.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

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

                            def send_to_clients_otherwise msg, elt
                              @clients.each{|cl|
                                if cl != elt
                                  cl.add_prefix(msg) unless msg.prefix
                                  cl << msg
                        Severity: Minor
                        Found in ndk/server.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

                        Avoid too many return statements within this method.
                        Open

                                return false
                        Severity: Major
                        Found in ndk/server.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return false
                          Severity: Major
                          Found in ndk/server.rb - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status