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'
- Read upRead up
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
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?
- Read upRead up
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)
- Read upRead up
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?
- Read upRead up
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,
- Read upRead up
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)
Method initialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(appid, secret, token_file, agentid, network_setting, jsapi_ticket_file)
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)
Method initialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(appid, secret, token_file, network_setting, jsapi_ticket_file, qcloud_setting)
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)
Method news_message_send
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def news_message_send(userid, title, description, link_url, pic_url)
Method initialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(client, appid, secret, token_file, record = nil)
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
- Read upRead up
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
- Read upRead up
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?
- Read upRead up
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
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)
- Read upRead up
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"