AndyObtiva/glimmer-dsl-tk

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

Summary

Maintainability
F
5 days
Test Coverage

File widget_proxy.rb has 598 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'yaml'
require 'glimmer/data_binding/tk/one_time_observer'
require 'glimmer/tk/widget'
require 'glimmer/tk/draggable_and_droppable'

Severity: Major
Found in lib/glimmer/tk/widget_proxy.rb - About 1 day to fix

    Class WidgetProxy has 52 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class WidgetProxy
          class << self
            def create(keyword, parent, args, &block)
              widget_proxy_class(keyword).new(keyword, parent, args, &block)
            end
    Severity: Major
    Found in lib/glimmer/tk/widget_proxy.rb - About 7 hrs to fix

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

            def handle_listener(listener_name, &listener)
              listener_name = listener_name.to_s
              # TODO return a listener registration object that has a deregister method
              if listener_name == 'destroy'
                # 'destroy' is a more reliable alternative listener binding to '<Destroy>'
      Severity: Minor
      Found in lib/glimmer/tk/widget_proxy.rb - About 4 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 grid has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

            def grid(options = {})
              @_visible = true
              options = options.stringify_keys
              options['rowspan'] = options.delete('row_span') if options.keys.include?('row_span')
              options['columnspan'] = options.delete('column_span') if options.keys.include?('column_span')
      Severity: Minor
      Found in lib/glimmer/tk/widget_proxy.rb - About 3 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 widget_custom_attribute_mapping has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def widget_custom_attribute_mapping
              # TODO consider extracting to modules/subclasses
              @widget_custom_attribute_mapping ||= {
                ::Tk::Tile::TButton => {
                  'image' => {
      Severity: Major
      Found in lib/glimmer/tk/widget_proxy.rb - About 3 hrs to fix

        Method widget_attribute_listener_installers has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def widget_attribute_listener_installers
                # TODO consider extracting to modules/subclasses
                @tk_widget_attribute_listener_installers ||= {
                  ::Tk::Tile::TCheckbutton => {
                    'variable' => lambda do |observer|
        Severity: Major
        Found in lib/glimmer/tk/widget_proxy.rb - About 3 hrs to fix

          Method set_attribute has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

                def set_attribute(attribute, *args)
                  begin
                    args = normalize_attribute_arguments(attribute, args)
                    widget_custom_attribute = widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]
                    if respond_to?(attribute_setter(attribute), super_only: true)
          Severity: Minor
          Found in lib/glimmer/tk/widget_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 set_attribute has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def set_attribute(attribute, *args)
                  begin
                    args = normalize_attribute_arguments(attribute, args)
                    widget_custom_attribute = widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]
                    if respond_to?(attribute_setter(attribute), super_only: true)
          Severity: Minor
          Found in lib/glimmer/tk/widget_proxy.rb - About 1 hr to fix

            Method handle_listener has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def handle_listener(listener_name, &listener)
                    listener_name = listener_name.to_s
                    # TODO return a listener registration object that has a deregister method
                    if listener_name == 'destroy'
                      # 'destroy' is a more reliable alternative listener binding to '<Destroy>'
            Severity: Minor
            Found in lib/glimmer/tk/widget_proxy.rb - About 1 hr to fix

              Method font= has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                    def font=(value)
                      if (value.is_a?(Symbol) || value.is_a?(String)) && FONTS_PREDEFINED.include?(value.to_s.downcase)
                        @tk.font = "tk_#{value}_font".camelcase(:upper)
                      else
                        @tk.font = value.is_a?(TkFont) ? value : TkFont.new(value)
              Severity: Minor
              Found in lib/glimmer/tk/widget_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 grid has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def grid(options = {})
                      @_visible = true
                      options = options.stringify_keys
                      options['rowspan'] = options.delete('row_span') if options.keys.include?('row_span')
                      options['columnspan'] = options.delete('column_span') if options.keys.include?('column_span')
              Severity: Minor
              Found in lib/glimmer/tk/widget_proxy.rb - About 1 hr to fix

                Method get_attribute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                      def get_attribute(attribute)
                        widget_custom_attribute = widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]
                        if respond_to?(attribute, super_only: true)
                          send(attribute)
                        elsif widget_custom_attribute
                Severity: Minor
                Found in lib/glimmer/tk/widget_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 attribute_argument_normalizers has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                      def attribute_argument_normalizers
                        color_normalizer = lambda do |args|
                          if args.size > 1 || args.first.is_a?(Numeric)
                            rgb = args
                            rgb = rgb.map(&:to_s).map(&:to_i)
                Severity: Minor
                Found in lib/glimmer/tk/widget_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 method_missing has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                      def method_missing(method, *args, &block)
                        method = method.to_s
                        attribute_name = method.sub(/=$/, '')
                        args = normalize_attribute_arguments(attribute_name, args)
                        if args.empty? && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]) || has_state?(method) || has_attributes_attribute?(method))
                Severity: Minor
                Found in lib/glimmer/tk/widget_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

                Consider simplifying this complex logical expression.
                Open

                        if args.empty? && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]) || has_state?(method) || has_attributes_attribute?(method))
                          get_attribute(method)
                        elsif method.end_with?('=') && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]) || has_state?(method) || has_attributes_attribute?(method))
                          set_attribute(attribute_name, *args)
                        else
                Severity: Major
                Found in lib/glimmer/tk/widget_proxy.rb - About 40 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                          elsif method.end_with?('=') && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]) || has_state?(method) || has_attributes_attribute?(method))
                            set_attribute(attribute_name, *args)
                          else
                            tk.send(method, *args, &block)
                  Severity: Major
                  Found in lib/glimmer/tk/widget_proxy.rb - About 40 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                              elsif args.size == 1 &&
                                    args.first.is_a?(String) &&
                                    !args.first.start_with?('#') &&
                                    (args.first.size == 3 || args.first.size == 6)  &&
                                    (args.first.chars.all? {|char| HEXADECIMAL_CHARACTERS.include?(char.downcase)})
                    Severity: Major
                    Found in lib/glimmer/tk/widget_proxy.rb - About 40 mins to fix

                      Method image_argument has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def image_argument(args)
                              if args.first.is_a?(::TkPhotoImage)
                                args.first
                              else
                                image_args = {}
                      Severity: Minor
                      Found in lib/glimmer/tk/widget_proxy.rb - About 25 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

                                ::Tk::Tile::TEntry => {
                                  'text' => {
                                    getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
                                    setter: {name: 'text=', invoker: lambda { |widget, args| @tk.textvariable&.value = args.first }},
                      Severity: Minor
                      Found in lib/glimmer/tk/widget_proxy.rb and 3 other locations - About 20 mins to fix
                      lib/glimmer/tk/widget_proxy.rb on lines 386..389
                      lib/glimmer/tk/widget_proxy.rb on lines 408..411
                      lib/glimmer/tk/widget_proxy.rb on lines 414..417

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

                      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

                                ::Tk::Tile::TSpinbox => {
                                  'text' => {
                                    getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
                                    setter: {name: 'text=', invoker: lambda { |widget, args| @tk.textvariable&.value = args.first }},
                      Severity: Minor
                      Found in lib/glimmer/tk/widget_proxy.rb and 3 other locations - About 20 mins to fix
                      lib/glimmer/tk/widget_proxy.rb on lines 386..389
                      lib/glimmer/tk/widget_proxy.rb on lines 402..405
                      lib/glimmer/tk/widget_proxy.rb on lines 414..417

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

                      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

                                ::Tk::Tile::TCombobox => {
                                  'text' => {
                                    getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
                                    setter: {name: 'text=', invoker: lambda { |widget, args| @tk.textvariable&.value = args.first }},
                      Severity: Minor
                      Found in lib/glimmer/tk/widget_proxy.rb and 3 other locations - About 20 mins to fix
                      lib/glimmer/tk/widget_proxy.rb on lines 402..405
                      lib/glimmer/tk/widget_proxy.rb on lines 408..411
                      lib/glimmer/tk/widget_proxy.rb on lines 414..417

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

                      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

                                ::Tk::Tile::TScale => {
                                  'variable' => {
                                    getter: {name: 'variable', invoker: lambda { |widget, args| @tk.variable&.value }},
                                    setter: {name: 'variable=', invoker: lambda { |widget, args| @tk.variable&.value = args.first }},
                      Severity: Minor
                      Found in lib/glimmer/tk/widget_proxy.rb and 3 other locations - About 20 mins to fix
                      lib/glimmer/tk/widget_proxy.rb on lines 386..389
                      lib/glimmer/tk/widget_proxy.rb on lines 402..405
                      lib/glimmer/tk/widget_proxy.rb on lines 408..411

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

                      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