Eric-Guo/wechat

View on GitHub

Showing 53 of 53 total issues

Class CorpApi has 49 methods (exceeds 20 allowed). Consider refactoring.
Open

  class CorpApi < ApiBase
    attr_reader :agentid

    def initialize(appid, secret, token_file, agentid, network_setting, jsapi_ticket_file)
      super()
Severity: Minor
Found in lib/wechat/corp_api.rb - About 6 hrs to fix

    Class Message has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Message
        class << self
          def from_hash(message_hash)
            new(message_hash)
          end
    Severity: Minor
    Found in lib/wechat/message.rb - About 4 hrs to fix

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

          private_class_method def self.loading_config!
            configs = config_from_file || config_from_environment
            configs.merge!(config_from_db)
      
            configs.transform_keys! do |key|
      Severity: Minor
      Found in lib/wechat/api_loader.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 load_controller_wechat has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def load_controller_wechat(account, opts = {})
            cfg = Wechat.config(account)
            self.token = opts[:token] || cfg.token
            self.appid = opts[:appid] || cfg.appid
            self.corpid = opts[:corpid] || cfg.corpid
      Severity: Minor
      Found in lib/action_controller/wechat_responder.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

      File responder.rb has 253 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'English'
      require 'rexml/document'
      
      module Wechat
        module Responder
      Severity: Minor
      Found in lib/wechat/responder.rb - About 2 hrs to fix

        Method on has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

              def on(message_type, with: nil, respond: nil, &block)
                config = respond.nil? ? {} : { respond: respond }
                config[:proc] = block if block_given?
        
                if with.present?
        Severity: Minor
        Found in lib/wechat/responder.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 config_from_file has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            private_class_method def self.config_from_file
              if defined?(::Rails)
                config_file = ENV.fetch('WECHAT_CONF_FILE') { Rails.root.join('config', 'wechat.yml') }
                resolve_config_file(config_file, Rails.env.to_s)
              else
        Severity: Minor
        Found in lib/wechat/api_loader.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 responder_for has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

              def responder_for(message)
                message_type = message[:MsgType].to_sym
                responders = user_defined_responders(message_type)
        
                case message_type
        Severity: Minor
        Found in lib/wechat/responder.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 resolve_config_file has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            private_class_method def self.resolve_config_file(config_file, env)
              return unless File.exist?(config_file)
        
              begin
                raw_data = load_yaml(ERB.new(File.read(config_file)).result)
        Severity: Minor
        Found in lib/wechat/api_loader.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 deep_recursive has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def deep_recursive(hash, &block)
              hash.inject({}) do |memo, val|
                key, value = *val
                case value.class.name
                when 'Hash'
        Severity: Minor
        Found in lib/wechat/message.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 match_responders has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def match_responders(responders, value)
                matched = responders.each_with_object({}) do |responder, memo|
                  condition = responder[:with]
        
                  if condition.nil?
        Severity: Minor
        Found in lib/wechat/responder.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 parse_response has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def parse_response(response, as_type)
              content_type = response.headers[:content_type]
              parse_as = {
                %r{^application/json} => :json,
                %r{^image/.*} => :file,
        Severity: Minor
        Found in lib/wechat/http_client.rb - About 1 hr to fix

          Method loading_config! has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private_class_method def self.loading_config!
                configs = config_from_file || config_from_environment
                configs.merge!(config_from_db)
          
                configs.transform_keys! do |key|
          Severity: Minor
          Found in lib/wechat/api_loader.rb - About 1 hr to fix

            Method on has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def on(message_type, with: nil, respond: nil, &block)
                    config = respond.nil? ? {} : { respond: respond }
                    config[:proc] = block if block_given?
            
                    if with.present?
            Severity: Minor
            Found in lib/wechat/responder.rb - About 1 hr to fix

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

                  def request(path, header = {}, &_block)
                    url_base = header.delete(:base) || base
                    as = header.delete(:as)
                    header['Accept'] ||= 'application/json'
                    response = yield("#{url_base}#{path}", header)
              Severity: Minor
              Found in lib/wechat/http_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 wechat_config_js has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def wechat_config_js(config_options = {})
                    account = config_options[:account]
              
                    # Get domain_name, api and app_id
                    if account.blank? || account == controller.class.wechat_cfg_account
              Severity: Minor
              Found in lib/wechat/helpers.rb - About 1 hr to fix

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

                      def responder_for(message)
                        message_type = message[:MsgType].to_sym
                        responders = user_defined_responders(message_type)
                
                        case message_type
                Severity: Minor
                Found in lib/wechat/responder.rb - About 1 hr to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  module Wechat
                    module Generators
                      class ConfigGenerator < Rails::Generators::Base
                        include ::Rails::Generators::Migration
                  
                  
                  Severity: Major
                  Found in lib/generators/wechat/config_generator.rb and 1 other location - About 1 hr to fix
                  lib/generators/wechat/session_generator.rb on lines 5..34

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 52.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  module Wechat
                    module Generators
                      class SessionGenerator < Rails::Generators::Base
                        include ::Rails::Generators::Migration
                  
                  
                  Severity: Major
                  Found in lib/generators/wechat/session_generator.rb and 1 other location - About 1 hr to fix
                  lib/generators/wechat/config_generator.rb on lines 5..34

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 52.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Method get_wechat_api has 9 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, network_setting, jsapi_ticket, qcloud_setting)
                  Severity: Major
                  Found in lib/action_controller/wechat_responder.rb - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language