danini-the-panini/mittsu-opengl

View on GitHub
lib/mittsu/glfw/window.rb

Summary

Maintainability
D
1 day
Test Coverage
F
27%

Method initialize has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(width, height, title, antialias: 0)
        ::GLFW.Init

        ::GLFW.WindowHint ::GLFW::OPENGL_PROFILE, ::GLFW::OPENGL_CORE_PROFILE
        ::GLFW.WindowHint ::GLFW::OPENGL_FORWARD_COMPAT, GL::TRUE
Severity: Minor
Found in lib/mittsu/glfw/window.rb - About 6 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 has too many lines. [55/30]
Open

      def initialize(width, height, title, antialias: 0)
        ::GLFW.Init

        ::GLFW.WindowHint ::GLFW::OPENGL_PROFILE, ::GLFW::OPENGL_CORE_PROFILE
        ::GLFW.WindowHint ::GLFW::OPENGL_FORWARD_COMPAT, GL::TRUE
Severity: Minor
Found in lib/mittsu/glfw/window.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class Window has 28 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Window
      attr_accessor :key_press_handler, :key_release_handler, :key_repeat_handler, :char_input_handler, :cursor_pos_handler, :mouse_button_press_handler, :mouse_button_release_handler, :scroll_handler, :framebuffer_size_handler

      def initialize(width, height, title, antialias: 0)
        ::GLFW.Init
Severity: Minor
Found in lib/mittsu/glfw/window.rb - About 3 hrs to fix

    Cyclomatic complexity for initialize is too high. [18/6]
    Open

          def initialize(width, height, title, antialias: 0)
            ::GLFW.Init
    
            ::GLFW.WindowHint ::GLFW::OPENGL_PROFILE, ::GLFW::OPENGL_CORE_PROFILE
            ::GLFW.WindowHint ::GLFW::OPENGL_FORWARD_COMPAT, GL::TRUE
    Severity: Minor
    Found in lib/mittsu/glfw/window.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

          def initialize(width, height, title, antialias: 0)
            ::GLFW.Init
    
            ::GLFW.WindowHint ::GLFW::OPENGL_PROFILE, ::GLFW::OPENGL_CORE_PROFILE
            ::GLFW.WindowHint ::GLFW::OPENGL_FORWARD_COMPAT, GL::TRUE
    Severity: Major
    Found in lib/mittsu/glfw/window.rb - About 2 hrs to fix

      Cyclomatic complexity for fire_joystick_button_event is too high. [7/6]
      Open

            def fire_joystick_button_event(joystick, button, pressed)
              if !@joystick_buttons[joystick][button] && pressed
                @joystick_button_press_handler.call(joystick, button) unless @joystick_button_press_handler.nil?
              elsif @joystick_buttons[joystick][button] && !pressed
                @joystick_button_release_handler.call(joystick, button) unless @joystick_button_release_handler.nil?
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

      An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

            def fire_joystick_button_event(joystick, button, pressed)
              if !@joystick_buttons[joystick][button] && pressed
                @joystick_button_press_handler.call(joystick, button) unless @joystick_button_press_handler.nil?
              elsif @joystick_buttons[joystick][button] && !pressed
                @joystick_button_release_handler.call(joystick, button) unless @joystick_button_release_handler.nil?
      Severity: Minor
      Found in lib/mittsu/glfw/window.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

      Unused block argument - mods. If it's necessary, use _ or _mods as an argument name to indicate that it won't be used.
      Open

              @mouse_button_callback = ::GLFW::create_callback(:GLFWmousebuttonfun) do |window_handle, button, action, mods|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - window_handle. If it's necessary, use _ or _window_handle as an argument name to indicate that it won't be used.
      Open

              @cursor_pos_callback = ::GLFW::create_callback(:GLFWcursorposfun) do |window_handle, xpos, ypos|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - window_handle. If it's necessary, use _ or _window_handle as an argument name to indicate that it won't be used.
      Open

              @scroll_callback = ::GLFW::create_callback(:GLFWscrollfun) do |window_handle, xoffset, yoffset|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - window_handle. If it's necessary, use _ or _window_handle as an argument name to indicate that it won't be used.
      Open

              @mouse_button_callback = ::GLFW::create_callback(:GLFWmousebuttonfun) do |window_handle, button, action, mods|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - scancode. If it's necessary, use _ or _scancode as an argument name to indicate that it won't be used.
      Open

              @key_callback = ::GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - window_handle. If it's necessary, use _ or _window_handle as an argument name to indicate that it won't be used.
      Open

              @key_callback = ::GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - mods. If it's necessary, use _ or _mods as an argument name to indicate that it won't be used.
      Open

              @key_callback = ::GLFW::create_callback(:GLFWkeyfun) do |window_handle, key, scancode, action, mods|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - window_handle. If it's necessary, use _ or _window_handle as an argument name to indicate that it won't be used.
      Open

              @char_callback = ::GLFW::create_callback(:GLFWcharfun) do |window_handle, codepoint|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      Unused block argument - window_handle. If it's necessary, use _ or _window_handle as an argument name to indicate that it won't be used.
      Open

              @frabuffer_size_callback = ::GLFW::create_callback(:GLFWframebuffersizefun) do |window_handle, new_width, new_height|
      Severity: Minor
      Found in lib/mittsu/glfw/window.rb by rubocop

      This cop checks for unused block arguments.

      Example:

      # bad
      
      do_something do |used, unused|
        puts used
      end
      
      do_something do |bar|
        puts :foo
      end
      
      define_method(:foo) do |bar|
        puts :baz
      end

      Example:

      #good
      
      do_something do |used, _unused|
        puts used
      end
      
      do_something do
        puts :foo
      end
      
      define_method(:foo) do |_bar|
        puts :baz
      end

      There are no issues that match your filters.

      Category
      Status