icyleaf/wechat-bot

View on GitHub
lib/wechat/bot/client.rb

Summary

Maintainability
D
2 days
Test Coverage

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

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

            There are no issues that match your filters.

            Category
            Status