Showing 46 of 47 total issues
File gateway_events.rb
has 343 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Discorb
module Gateway
#
# Represents an event.
# @abstract
Method initialize
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def initialize(name, tone: 0)
if EmojiTable::DISCORD_TO_UNICODE.key?(name)
@name = name
@value = EmojiTable::DISCORD_TO_UNICODE[name]
elsif EmojiTable::UNICODE_TO_DISCORD.key?(name)
- 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 setup_commands
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
def setup_commands(token = nil, guild_ids: nil)
Async do
@token ||= token
@http = HTTP.new(self)
global_commands =
Method edit
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def edit(
name: Discorb::Unset,
event_type: Discorb::Unset,
actions: Discorb::Unset,
enabled: Discorb::Unset,
- 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 modify_option_map
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
def modify_option_map(option_map, options, guild, members, attachments)
options ||= []
options.each do |option|
val =
case option[:type]
Method setup_commands
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def setup_commands(token = nil, guild_ids: nil)
Async do
@token ||= token
@http = HTTP.new(self)
global_commands =
- 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 build_version_sidebar
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_version_sidebar(dir, version)
raw = File.read("template-replace/resources/version_list.html")
template = raw.match(/<!--template-->(.*)<!--endtemplate-->/m)[1]
raw.gsub!(template, "")
res = +""
Method modify_option_map
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def modify_option_map(option_map, options, guild, members, attachments)
options ||= []
options.each do |option|
val =
case option[:type]
- 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 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(client, data)
@client = client
@data = data
if data.key?(:user_id)
@user_id = Snowflake.new(data[:user_id])
Method initialize
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def initialize(client, data)
@client = client
@data = data
if data.key?(:user_id)
@user_id = Snowflake.new(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 post
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def post(
content = nil,
tts: false,
embed: nil,
embeds: nil,
Method _set_data
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _set_data(data)
super
Sync do
name, options =
Discorb::CommandInteraction::ChatInputCommand.get_command_data(data)
Method initialize_hash
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize_hash(data)
@title = data[:title]
@description = data[:description]
@url = data[:url]
@timestamp = data[:timestamp] && Time.iso8601(data[:timestamp])
Method yard_replace
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def yard_replace(dir, version)
sha = `git rev-parse HEAD`.strip
tag = `git describe --exact-match #{sha}`
tag = tag.empty? ? "(main)" : tag.strip
Dir.glob("#{dir}/**/*.html") do |file|
Method _set_data
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _set_data(data)
@data = data
@guild_id = data[:guild_id]
@channel_id = data[:channel_id]
@user_id = data[:user_id]
Similar blocks of code found in 2 locations. Consider refactoring. Open
def replace_title(dir)
regex =
%r{(?:<h1 id="full_list_header">|<title>)([a-zA-Z ]+?)(?:</title>|</h1>)}
Dir.glob("#{dir}/*.html") do |file|
- 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 51.
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 replace_sidebar_name(dir)
regex = %r{<a target="_self" href="(.+)_list\.html">\s*([a-zA-Z ]+?)\s*</a>}
Dir.glob("#{dir}/*_list.html") do |file|
content = File.read(file)
- 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 51.
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 edit_original_message
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def edit_original_message(
content = nil,
embed: nil,
embeds: nil,
attachment: 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 to_hash
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def to_hash
# @type var ret: Hash[untyped, untyped]
ret = { type: "rich" }
ret[:title] = @title if @title
ret[:description] = @description if @description
- 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 edit
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def edit(
name: Discorb::Unset,
position: Discorb::Unset,
bitrate: Discorb::Unset,
user_limit: Discorb::Unset,
- 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"