Eric-Guo/wechat

View on GitHub
lib/wechat/api_loader.rb

Summary

Maintainability
C
1 day
Test Coverage
C
73%

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

    Empty line detected around arguments.
    Open

    
          # create config object using raw config data
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    Empty line detected around arguments.
    Open

    
          configs.transform_keys! do |key|
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    Empty line detected around arguments.
    Open

    
          if defined?(::Rails)
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    Empty line detected around arguments.
    Open

    
          environment = defined?(::Rails) ? Rails.env.to_s : ENV.fetch('RAILS_ENV', 'development')
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    Empty line detected around arguments.
    Open

    
          begin
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    Empty line detected around arguments.
    Open

    
            cfg.transform_keys! do |sub_key|
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    Empty line detected around arguments.
    Open

    
          configs.each_value do |cfg|
    Severity: Minor
    Found in lib/wechat/api_loader.rb by rubocop

    This cops checks if empty lines exist around the arguments of a method invocation.

    Example:

    # bad
    do_something(
      foo
    
    )
    
    process(bar,
    
            baz: qux,
            thud: fred)
    
    some_method(
    
      [1,2,3],
      x: y
    )
    
    # good
    do_something(
      foo
    )
    
    process(bar,
            baz: qux,
            thud: fred)
    
    some_method(
      [1,2,3],
      x: y
    )

    There are no issues that match your filters.

    Category
    Status