Eric-Guo/wechat

View on GitHub

Showing 53 of 53 total issues

Method with has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def self.with(options)
      account = options[:account] || :default
      c = ApiLoader.config(account)

      token_file = options[:token_file] || c.access_token.presence || '/var/tmp/wechat_access_token'
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 load_controller_wechat has 26 lines of code (exceeds 25 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 1 hr to fix

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

        def run_responder(request)
          self.class.responder_for(request) do |responder, *args|
            responder ||= self.class.user_defined_responders(:fallback).first
    
            next if responder.nil?
    Severity: Minor
    Found in lib/wechat/responder.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 wechat_oauth2 has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def wechat_oauth2(scope = 'snsapi_base', page_url = nil, account = nil, &block)
          # ensure wechat initialization
          self.class.corpid || self.class.appid || self.class.wechat
    
          api = wechat(account)
    Severity: Minor
    Found in lib/wechat/controller_api.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 app_config_is_valid has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def app_config_is_valid
        if self[:appid].present?
          # public account
          errors.add(:secret, 'cannot be nil when appid is set') if self[:secret].blank?
        elsif self[:corpid].present?
    Severity: Minor
    Found in lib/generators/wechat/templates/app/models/wechat_config.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 parse_response has a Cognitive Complexity of 9 (exceeds 5 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 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 initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def initialize(appid, secret, token_file, network_setting, jsapi_ticket_file, record = nil)
    Severity: Minor
    Found in lib/wechat/api.rb - About 45 mins to fix

      Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

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

        Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def initialize(timeout, skip_verify_ssl, proxy_url, proxy_port, proxy_username, proxy_password)
        Severity: Minor
        Found in lib/wechat/network_setting.rb - About 45 mins to fix

          Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def initialize(appid, secret, token_file, network_setting, jsapi_ticket_file, qcloud_setting)
          Severity: Minor
          Found in lib/wechat/mp_api.rb - About 45 mins to fix

            Method tcb_do_upload_file has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                  def tcb_do_upload_file(q_path, upload_url, signature, x_cos_security_token, x_cos_meta_fileid, file)
            Severity: Minor
            Found in lib/wechat/concern/qcloud.rb - About 45 mins to fix

              Method news_message_send has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def news_message_send(userid, title, description, link_url, pic_url)
              Severity: Minor
              Found in lib/wechat/corp_api.rb - About 35 mins to fix

                Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                      def initialize(client, appid, secret, token_file, record = nil)
                Severity: Minor
                Found in lib/wechat/token/access_token_base.rb - About 35 mins to fix

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

                        def ticket(tries = 2)
                          # Possible two worker running, one worker refresh ticket, other unaware, so must read every time
                          read_ticket_from_store
                          refresh if remain_life_seconds < @random_generator.rand(30..(3 * 60))
                          access_ticket
                  Severity: Minor
                  Found in lib/wechat/ticket/jsapi_base.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 token has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def token(tries = 2)
                          # Possible two worker running, one worker refresh ticket, other unaware, so must read every time
                          read_qcloud_token_from_store
                          refresh if remain_life_seconds < @random_generator.rand(30..(3 * 60))
                          qcloud_token
                  Severity: Minor
                  Found in lib/wechat/qcloud/token.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 post_body has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def post_body
                        if request.media_type == 'application/json'
                          data_hash = params
                  
                          if @we_encrypt_mode && data['Encrypt'].present?
                  Severity: Minor
                  Found in lib/wechat/responder.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

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

                        def ticket(tries = 2)
                          # Possible two worker running, one worker refresh ticket, other unaware, so must read every time
                          read_ticket_from_store
                          refresh if remain_life_seconds < @random_generator.rand(30..(3 * 60))
                          access_ticket
                  Severity: Minor
                  Found in lib/wechat/ticket/jsapi_base.rb and 1 other location - About 25 mins to fix
                  lib/wechat/qcloud/token.rb on lines 22..29

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

                  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

                        def token(tries = 2)
                          # Possible two worker running, one worker refresh ticket, other unaware, so must read every time
                          read_qcloud_token_from_store
                          refresh if remain_life_seconds < @random_generator.rand(30..(3 * 60))
                          qcloud_token
                  Severity: Minor
                  Found in lib/wechat/qcloud/token.rb and 1 other location - About 25 mins to fix
                  lib/wechat/ticket/jsapi_base.rb on lines 18..25

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

                  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 with_access_token has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def with_access_token(params = {}, tries = 2)
                        params ||= {}
                        yield(params.merge(access_token: access_token.token))
                      rescue AccessTokenExpiredError
                        access_token.refresh
                  Severity: Minor
                  Found in lib/wechat/api_base.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 missing_necessary_attributes? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def missing_necessary_attributes?
                          return true unless record.respond_to?(:access_token)
                          return true unless record.respond_to?(:token_expires_in)
                          return true unless record.respond_to?(:got_token_at)
                  
                  
                  Severity: Minor
                  Found in lib/wechat/token/access_token_base.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

                  Severity
                  Category
                  Status
                  Source
                  Language