discorb-lib/discorb

View on GitHub

Showing 46 of 47 total issues

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,
Severity: Minor
Found in lib/discorb/interaction/root.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 _set_data has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def _set_data(data)
      super
      @name = data[:name]
      @messages = {}
      @attachments = {}
Severity: Minor
Found in lib/discorb/interaction/command.rb - About 1 hr to fix

    Method initialize has 27 lines of code (exceeds 25 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)
    Severity: Minor
    Found in lib/discorb/emoji.rb - About 1 hr to fix

      Method edit_original_message has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def edit_original_message(
            content = nil,
            embed: nil,
            embeds: nil,
            attachment: nil,
      Severity: Minor
      Found in lib/discorb/interaction/root.rb - About 1 hr to fix

        Method initialize has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def initialize(client, data, before, after)
                @client = client
                @data = data
                @before = before
                @after = after
        Severity: Minor
        Found in lib/discorb/gateway_events.rb - About 1 hr to fix

          Method yard_replace has a Cognitive Complexity of 9 (exceeds 5 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|
          Severity: Minor
          Found in template-replace/scripts/yard_replace.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 a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(
                title = nil,
                description = nil,
                color: nil,
                url: nil,
          Severity: Minor
          Found in lib/discorb/embed.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 post has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def post(
                content = nil,
                tts: false,
                embed: nil,
                embeds: nil,
          Severity: Minor
          Found in lib/discorb/interaction/root.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 edit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def edit(
                  name: Discorb::Unset,
                  description: Discorb::Unset,
                  tag: Discorb::Unset,
                  reason: Discorb::Unset
          Severity: Minor
          Found in lib/discorb/sticker.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 to_hash has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_hash(other = nil)
                payload = { parse: %w[everyone roles users] }
                replied_user = nil_merge(@replied_user, other&.replied_user)
                everyone = nil_merge(@everyone, other&.everyone)
                roles = nil_merge(@roles, other&.roles)
          Severity: Minor
          Found in lib/discorb/allowed_mentions.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

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

              class Thumbnail < Entry
                # @return [String] The url of thumbnail.
                attr_accessor :url
                # @return [String] The proxy url of thumbnail.
                # @return [nil] The Thumbnail object wasn't created from gateway.
          Severity: Minor
          Found in lib/discorb/embed.rb and 1 other location - About 50 mins to fix
          lib/discorb/embed.rb on lines 269..307

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

          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

              class Image < Entry
                # @return [String] The url of image.
                attr_accessor :url
                # @return [String] The proxy url of image.
                # @return [nil] The Image object wasn't created from gateway.
          Severity: Minor
          Found in lib/discorb/embed.rb and 1 other location - About 50 mins to fix
          lib/discorb/embed.rb on lines 314..352

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

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

              def wait(path)
                # return if path.url.start_with?("https://")
                if @global && @global > Time.now.to_f
                  time = @global - Time.now.to_f
                  @client.logger.info(
          Severity: Minor
          Found in lib/discorb/rate_limit.rb - About 45 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 modify_option_map has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  def modify_option_map(option_map, options, guild, members, attachments)
          Severity: Minor
          Found in lib/discorb/interaction/command.rb - About 35 mins to fix

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

                  def message_command(
                    command_name,
                    guild_ids: nil,
                    dm_permission: true,
                    default_permission: nil,
            Severity: Minor
            Found in lib/discorb/app_command/handler.rb and 1 other location - About 35 mins to fix
            lib/discorb/app_command/handler.rb on lines 180..199

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

            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 _set_data has a Cognitive Complexity of 7 (exceeds 5 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]
            Severity: Minor
            Found in lib/discorb/voice_state.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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def initialize(client, data, before, after)
                    @client = client
                    @data = data
                    @before = before
                    @after = after
            Severity: Minor
            Found in lib/discorb/gateway_events.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 edit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def edit(name: Discorb::Unset, avatar: Discorb::Unset)
                  Async do
                    payload = {}
                    payload[:username] = name unless name == Discorb::Unset
                    if avatar == Discorb::Unset
            Severity: Minor
            Found in lib/discorb/user.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 _set_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _set_data(data, gateway)
                  @code = data[:code]
                  if gateway
                    @channel_data = { id: data[:channel_id] }
                    @guild_data = { id: data[:guild_id] }
            Severity: Minor
            Found in lib/discorb/invite.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 user_command(
                    command_name,
                    guild_ids: nil,
                    dm_permission: true,
                    default_permission: nil,
            Severity: Minor
            Found in lib/discorb/app_command/handler.rb and 1 other location - About 35 mins to fix
            lib/discorb/app_command/handler.rb on lines 143..162

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

            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

            Severity
            Category
            Status
            Source
            Language