discorb-lib/discorb

View on GitHub

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
Severity: Minor
Found in lib/discorb/gateway_events.rb - About 4 hrs to fix

    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)
    Severity: Minor
    Found in lib/discorb/emoji.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 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 =
    Severity: Major
    Found in lib/discorb/app_command/handler.rb - About 2 hrs to fix

      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,
      Severity: Minor
      Found in lib/discorb/automod.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 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]
      Severity: Minor
      Found in lib/discorb/interaction/command.rb - About 1 hr to fix

        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 =
        Severity: Minor
        Found in lib/discorb/app_command/handler.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 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 = +""
        Severity: Minor
        Found in template-replace/scripts/version.rb - About 1 hr to fix

          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]
          Severity: Minor
          Found in lib/discorb/interaction/command.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 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])
          Severity: Minor
          Found in lib/discorb/gateway_events.rb - About 1 hr to fix

            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])
            Severity: Minor
            Found in lib/discorb/gateway_events.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 post has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

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

              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)
              Severity: Minor
              Found in lib/discorb/interaction/autocomplete.rb - About 1 hr to fix

                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])
                Severity: Minor
                Found in lib/discorb/embed.rb - About 1 hr to fix

                  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|
                  Severity: Minor
                  Found in template-replace/scripts/yard_replace.rb - About 1 hr to fix

                    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]
                    Severity: Minor
                    Found in lib/discorb/voice_state.rb - About 1 hr to fix

                      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|
                      Severity: Major
                      Found in template-replace/scripts/locale_ja.rb and 1 other location - About 1 hr to fix
                      template-replace/scripts/locale_ja.rb on lines 19..34

                      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

                      Further Reading

                      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)
                      Severity: Major
                      Found in template-replace/scripts/locale_ja.rb and 1 other location - About 1 hr to fix
                      template-replace/scripts/locale_ja.rb on lines 38..54

                      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

                      Further Reading

                      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 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
                      Severity: Minor
                      Found in lib/discorb/embed.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 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,
                      Severity: Minor
                      Found in lib/discorb/channel/voice.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

                      Severity
                      Category
                      Status
                      Source
                      Language