AndyObtiva/glimmer-dsl-tk

View on GitHub
lib/glimmer/tk/text_proxy.rb

Summary

Maintainability
F
3 days
Test Coverage

File text_proxy.rb has 368 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'glimmer/tk/widget_proxy'

module Glimmer
  module Tk
    # Proxy for Tk::Text
Severity: Minor
Found in lib/glimmer/tk/text_proxy.rb - About 4 hrs to fix

    Class TextProxy has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class TextProxy < WidgetProxy
          ALL_TAG = '__all__'
          FORMAT_DEFAULT_MAP = {
            'justify' => 'left',
          }
    Severity: Minor
    Found in lib/glimmer/tk/text_proxy.rb - About 4 hrs to fix

      Method remove_font_format has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def remove_font_format(region_start, region_end, font_option, value)
              applied_font_format_tags_and_regions(region_start, region_end).each do |tag, tag_region_start, tag_region_end|
                if tag
                  bigger_region_tag = @tk.tag_ranges(tag).any? do |range_start, range_end|
                    text_index_less_than_other_text_index?(range_start, tag_region_start) || text_index_greater_than_other_text_index?(range_end, tag_region_end)
      Severity: Minor
      Found in lib/glimmer/tk/text_proxy.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 add_font_format has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_font_format(region_start, region_end, font_option, value)
              applied_font_format_tags_and_regions(region_start, region_end).each do |tag, tag_region_start, tag_region_end|
                if tag
                  bigger_region_tag = @tk.tag_ranges(tag).any? do |range_start, range_end|
                    text_index_less_than_other_text_index?(range_start, tag_region_start) || text_index_greater_than_other_text_index?(range_end, tag_region_end)
      Severity: Minor
      Found in lib/glimmer/tk/text_proxy.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 handle_listener has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def handle_listener(listener_name, &listener)
              case listener_name.to_s.downcase
              when '<<modified>>', '<modified>', 'modified'
                modified_listener = Proc.new do |*args|
                  @modified_count ||= 0
      Severity: Minor
      Found in lib/glimmer/tk/text_proxy.rb - About 1 hr to fix

        Method remove_font_format has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def remove_font_format(region_start, region_end, font_option, value)
                applied_font_format_tags_and_regions(region_start, region_end).each do |tag, tag_region_start, tag_region_end|
                  if tag
                    bigger_region_tag = @tk.tag_ranges(tag).any? do |range_start, range_end|
                      text_index_less_than_other_text_index?(range_start, tag_region_start) || text_index_greater_than_other_text_index?(range_end, tag_region_end)
        Severity: Minor
        Found in lib/glimmer/tk/text_proxy.rb - About 1 hr to fix

          Method add_font_format has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def add_font_format(region_start, region_end, font_option, value)
                  applied_font_format_tags_and_regions(region_start, region_end).each do |tag, tag_region_start, tag_region_end|
                    if tag
                      bigger_region_tag = @tk.tag_ranges(tag).any? do |range_start, range_end|
                        text_index_less_than_other_text_index?(range_start, tag_region_start) || text_index_greater_than_other_text_index?(range_end, tag_region_end)
          Severity: Minor
          Found in lib/glimmer/tk/text_proxy.rb - About 1 hr to fix

            Method handle_listener has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                  def handle_listener(listener_name, &listener)
                    case listener_name.to_s.downcase
                    when '<<modified>>', '<modified>', 'modified'
                      modified_listener = Proc.new do |*args|
                        @modified_count ||= 0
            Severity: Minor
            Found in lib/glimmer/tk/text_proxy.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 applied_font_format_tags_and_regions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                  def applied_font_format_tags_and_regions(region_start, region_end)
                    lines = value.split("\n")
                    tags_and_regions = []
                    all_tag_names = (@tk.tag_names - ['sel', ALL_TAG]).select {|tag_name| tag_name.include?('_font_')}
                    (region_start.to_i..region_end.to_i).each do |line_number|
            Severity: Minor
            Found in lib/glimmer/tk/text_proxy.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 applied_format_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def applied_format_value(text_index = nil, option)
                    text_index ||= @tk.index('insert')
                    region_start = text_index
                    region_end = text_index
                    tag_names = @tk.tag_names - ['sel', ALL_TAG]
            Severity: Minor
            Found in lib/glimmer/tk/text_proxy.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 applied_font_format_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def applied_font_format_value(text_index = nil, font_option)
                    text_index ||= @tk.index('insert')
                    region_start = text_index
                    region_end = @tk.index("#{text_index} + 1 chars")
                    tag_names = applied_font_format_tags_and_regions(region_start, region_end).map(&:first)
            Severity: Minor
            Found in lib/glimmer/tk/text_proxy.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 4 locations. Consider refactoring.
            Open

                  def text_index_greater_than_other_text_index?(region1, region2)
                    region1_parts = region1.to_s.split('.')
                    region2_parts = region2.to_s.split('.')
                    return true if region1_parts.first.to_i > region2_parts.first.to_i
                    return false if region1_parts.first.to_i < region2_parts.first.to_i
            Severity: Major
            Found in lib/glimmer/tk/text_proxy.rb and 3 other locations - About 45 mins to fix
            lib/glimmer/tk/text_proxy.rb on lines 387..392
            lib/glimmer/tk/text_proxy.rb on lines 395..400
            lib/glimmer/tk/text_proxy.rb on lines 411..416

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

            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 4 locations. Consider refactoring.
            Open

                  def text_index_less_than_other_text_index?(region1, region2)
                    region1_parts = region1.to_s.split('.')
                    region2_parts = region2.to_s.split('.')
                    return true if region1_parts.first.to_i < region2_parts.first.to_i
                    return false if region1_parts.first.to_i > region2_parts.first.to_i
            Severity: Major
            Found in lib/glimmer/tk/text_proxy.rb and 3 other locations - About 45 mins to fix
            lib/glimmer/tk/text_proxy.rb on lines 395..400
            lib/glimmer/tk/text_proxy.rb on lines 403..408
            lib/glimmer/tk/text_proxy.rb on lines 411..416

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

            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 4 locations. Consider refactoring.
            Open

                  def text_index_less_than_or_equal_to_other_text_index?(region1, region2)
                    region1_parts = region1.to_s.split('.')
                    region2_parts = region2.to_s.split('.')
                    return true if region1_parts.first.to_i < region2_parts.first.to_i
                    return false if region1_parts.first.to_i > region2_parts.first.to_i
            Severity: Major
            Found in lib/glimmer/tk/text_proxy.rb and 3 other locations - About 45 mins to fix
            lib/glimmer/tk/text_proxy.rb on lines 387..392
            lib/glimmer/tk/text_proxy.rb on lines 403..408
            lib/glimmer/tk/text_proxy.rb on lines 411..416

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

            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 4 locations. Consider refactoring.
            Open

                  def text_index_greater_than_or_equal_to_other_text_index?(region1, region2)
                    region1_parts = region1.to_s.split('.')
                    region2_parts = region2.to_s.split('.')
                    return true if region1_parts.first.to_i > region2_parts.first.to_i
                    return false if region1_parts.first.to_i < region2_parts.first.to_i
            Severity: Major
            Found in lib/glimmer/tk/text_proxy.rb and 3 other locations - About 45 mins to fix
            lib/glimmer/tk/text_proxy.rb on lines 387..392
            lib/glimmer/tk/text_proxy.rb on lines 395..400
            lib/glimmer/tk/text_proxy.rb on lines 403..408

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

            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

                              font = @tk.tag_cget(tag, 'font')
                              remove_format(range_start, range_end, 'font', font)
                              add_format(tag_region_end, range_end, 'font', font)
                              font_clone = clone_font(font)
                              font_clone.send("#{font_option}=", value)
            Severity: Minor
            Found in lib/glimmer/tk/text_proxy.rb and 1 other location - About 25 mins to fix
            lib/glimmer/tk/text_proxy.rb on lines 281..286

            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

            Further Reading

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

                              font = @tk.tag_cget(tag, 'font')
                              remove_format(range_start, range_end, 'font', font)
                              add_format(range_start, tag_region_start, 'font', font)
                              font_clone = clone_font(font)
                              font_clone.send("#{font_option}=", value)
            Severity: Minor
            Found in lib/glimmer/tk/text_proxy.rb and 1 other location - About 25 mins to fix
            lib/glimmer/tk/text_proxy.rb on lines 288..293

            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

            Further Reading

            There are no issues that match your filters.

            Category
            Status