icyleaf/wechat-bot

View on GitHub

Showing 16 of 16 total issues

File client.rb has 348 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "rqrcode"
require "logger"
require "uri"

module WeChat::Bot
Severity: Minor
Found in lib/wechat/bot/client.rb - About 4 hrs to fix

    Class Client has 26 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Client
        def initialize(bot)
          @bot = bot
          clone!
        end
    Severity: Minor
    Found in lib/wechat/bot/client.rb - About 3 hrs to fix

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

        class Contact
          # 联系人分类
          module Kind
            User = :user
            Group = :group
      Severity: Minor
      Found in lib/wechat/bot/contact.rb - About 2 hrs to fix

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

            def start_runloop_thread
              @is_alive = true
              retry_count = 0
        
              Thread.new do
        Severity: Minor
        Found in lib/wechat/bot/client.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 has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def start
              @client.login
              @client.contacts
        
              @contact_list.each do |c|
        Severity: Minor
        Found in lib/wechat/bot/core.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 default_config has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.default_config
              {
                # Bot Configurations
                verbose: false,
                fireman: 'filehelper',
        Severity: Minor
        Found in lib/wechat/bot/configuration.rb - About 1 hr to fix

          Method login has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def login
                return @bot.logger.info("你已经登录") if logged?
          
                check_count = 0
                until logged?
          Severity: Minor
          Found in lib/wechat/bot/client.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 sync_messages has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def sync_messages
                query = {
                  "sid" => store(:sid),
                  "skey" => store(:skey),
                  "pass_ticket" => store(:pass_ticket)
          Severity: Minor
          Found in lib/wechat/bot/client.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 login has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def login
                return @bot.logger.info("你已经登录") if logged?
          
                check_count = 0
                until logged?
          Severity: Minor
          Found in lib/wechat/bot/client.rb - About 1 hr to fix

            Method start_runloop_thread has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def start_runloop_thread
                  @is_alive = true
                  retry_count = 0
            
                  Thread.new do
            Severity: Minor
            Found in lib/wechat/bot/client.rb - About 1 hr to fix

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

                  def sync_messages
                    query = {
                      "sid" => store(:sid),
                      "skey" => store(:skey),
                      "pass_ticket" => store(:pass_ticket)
              Severity: Minor
              Found in lib/wechat/bot/client.rb - About 1 hr to fix

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

                    def dispatch(event, message = nil, *args)
                      threads = []
                
                      if handlers = find(event, message)
                        already_run = Set.new
                Severity: Minor
                Found in lib/wechat/bot/handler_list.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 find has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def find(**args)
                      @mutex.synchronize do
                        return @cache[args[:username]] if args[:username]
                
                        if args[:nickname]
                Severity: Minor
                Found in lib/wechat/bot/contact_list.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def initialize(bot, event, pattern, options = {}, &block)
                Severity: Minor
                Found in lib/wechat/bot/handler.rb - About 35 mins to fix

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

                      def store(*args)
                        return @store[args[0].to_sym] = args[1] if args.size == 2
                  
                        if args.size == 1
                          obj = args[0]
                  Severity: Minor
                  Found in lib/wechat/bot/client.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 parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def parse(raw, update = false)
                        @raw = raw
                  
                        parse_kind
                        parse_members
                  Severity: Minor
                  Found in lib/wechat/bot/contact.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