File twitter_sync.rb
has 762 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'http/uri'
class TwitterSync
STATUS_URL_TEMPLATE = 'https://twitter.com/_/status/%s'.freeze
Method process_webhook
has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring. Open
def process_webhook(channel)
Rails.logger.debug { 'import tweet' }
ticket = nil
if @payload['direct_message_events'].present? && channel.options[:sync][:direct_messages][:group_id].present?
@payload['direct_message_events'].each do |item|
- 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 to_article_webhook
has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring. Open
def to_article_webhook(item, user, ticket, channel)
Rails.logger.debug { 'Create article from tweet...' }
Rails.logger.debug { item.inspect }
Rails.logger.debug { user.inspect }
- 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 to_article_webhook
has 155 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_article_webhook(item, user, ticket, channel)
Rails.logger.debug { 'Create article from tweet...' }
Rails.logger.debug { item.inspect }
Rails.logger.debug { user.inspect }
Method preferences_cleanup
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def self.preferences_cleanup(preferences)
# replace Twitter::NullObject with nill to prevent elasticsearch index issue
preferences.each do |key, value|
- 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
Class TwitterSync
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class TwitterSync
STATUS_URL_TEMPLATE = 'https://twitter.com/_/status/%s'.freeze
DM_URL_TEMPLATE = 'https://twitter.com/messages/%s'.freeze
Method to_ticket
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_ticket(tweet, user, group_id, channel)
UserInfo.current_user_id = user.id
Rails.logger.debug { 'Create ticket from tweet...' }
Rails.logger.debug { tweet.inspect }
Method to_user_webhook
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def to_user_webhook(user_id, payload_user = nil)
user_payload = if payload_user && payload_user['id'].to_s == user_id.to_s
payload_user
else
to_user_webhook_data(user_id)
- 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 to_user_webhook
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_user_webhook(user_id, payload_user = nil)
user_payload = if payload_user && payload_user['id'].to_s == user_id.to_s
payload_user
else
to_user_webhook_data(user_id)
Method to_article
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_article(tweet, user, ticket, channel)
Rails.logger.debug { 'Create article from tweet...' }
Rails.logger.debug { tweet.inspect }
Rails.logger.debug { user.inspect }
Method to_user
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_user(tweet)
Rails.logger.debug { 'Create user from tweet...' }
Rails.logger.debug { tweet.inspect }
Method process_webhook
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_webhook(channel)
Rails.logger.debug { 'import tweet' }
ticket = nil
if @payload['direct_message_events'].present? && channel.options[:sync][:direct_messages][:group_id].present?
@payload['direct_message_events'].each do |item|
Method to_user
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def to_user(tweet)
Rails.logger.debug { 'Create user from tweet...' }
Rails.logger.debug { tweet.inspect }
- 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 to_group
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def to_group(tweet, group_id, channel)
Rails.logger.debug { 'import tweet' }
ticket = 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 preferences_cleanup
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.preferences_cleanup(preferences)
# replace Twitter::NullObject with nill to prevent elasticsearch index issue
preferences.each do |key, value|
Method locale_sender?
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def locale_sender?(tweet)
tweet_user = user(tweet)
Channel.where(area: 'Twitter::Account').each do |local_channel|
next if !local_channel.options
next if !local_channel.options[:user]
- 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 get_state
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_state(channel, tweet, ticket = nil)
user_id = if tweet.is_a?(Hash)
if tweet['user'] && tweet['user']['id']
tweet['user']['id']
- 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 to_ticket
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def to_ticket(tweet, user, group_id, channel)
UserInfo.current_user_id = user.id
Rails.logger.debug { 'Create ticket from tweet...' }
Rails.logger.debug { tweet.inspect }
- 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
Avoid deeply nested control flow statements. Open
if local_media['expanded_url'].present?
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
elsif local_media['display_url']
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
end
Avoid deeply nested control flow statements. Open
if local_media['expanded_url'].present?
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
elsif local_media['display_url']
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
end
Similar blocks of code found in 2 locations. Consider refactoring. Open
if user_data[:image_source]
avatar = Avatar.add(
object: 'User',
o_id: user.id,
url: user_data[:image_source],
- 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 43.
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
user = User.find(auth.user_id)
map = {
note: 'description',
web: 'url',
address: 'location',
- 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 41.
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
user = User.find(auth.user_id)
map = {
note: 'description',
web: 'website',
address: 'location',
- 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 41.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if local_media['url'].present?
if local_media['expanded_url'].present?
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
elsif local_media['display_url']
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
- 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 38.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if local_media['url'].present?
if local_media['expanded_url'].present?
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['expanded_url'])
elsif local_media['display_url']
text.gsub!(%r{#{Regexp.quote(local_media['url'])}}, local_media['display_url'])
- 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 38.
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