midori-rb/midori.rb

View on GitHub

Showing 14 of 15 total issues

Method receive has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def receive(request, connection = nil)
    @routes[request.method].each do |route|
      params = route.path.params(request.path)
      next unless params # Skip if not matched
      request.params = params
Severity: Minor
Found in lib/midori/api_engine.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

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

  def receive_data(socket)
    begin
      @request.ip, @request.port = @peer_addr
      if @request.parsed? && !(@request.body_parsed?)
        data = socket.read @request.body.bytesize - @request.header['Content-Length']
Severity: Minor
Found in lib/midori/server.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.

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

  def parse(data)
    # Call parser if header not parsed
    if @parsed
      @body += data
    else
Severity: Minor
Found in lib/midori/request.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 receive has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Confirmed

  def receive(request, connection = nil)
    @routes[request.method].each do |route|
      params = route.path.params(request.path)
      next unless params # Skip if not matched
      request.params = params
Severity: Minor
Found in lib/midori/api_engine.rb - About 1 hr to fix

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

      def initialize
        @header = HTTPHeader.new
        @parsed = false
        @body_parsed = false
        @is_websocket = false
    Severity: Minor
    Found in lib/midori/request.rb - About 1 hr to fix

      Method send has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Confirmed

        def send(msg)
          output = []
          payload_length = []
          if msg.size < 126
            payload_length << msg.size
      Severity: Minor
      Found in lib/midori/websocket.rb - About 1 hr to fix

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

          def receive_data(socket)
            begin
              @request.ip, @request.port = @peer_addr
              if @request.parsed? && !(@request.body_parsed?)
                data = socket.read @request.body.bytesize - @request.header['Content-Length']
        Severity: Minor
        Found in lib/midori/server.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 parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def parse(data)
            # Call parser if header not parsed
            if @parsed
              @body += data
            else
        Severity: Minor
        Found in lib/midori/request.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 middleware_exec has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          private def middleware_exec(middlewares, clean_room, request, response=nil)
            result = response.nil? ? request : response
            middlewares.each do |middleware|
              if response.nil?
                result = Midori::Sandbox.run(
        Severity: Minor
        Found in lib/midori/api_engine.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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def initialize
            @header = HTTPHeader.new
            @parsed = false
            @body_parsed = false
            @is_websocket = false
        Severity: Minor
        Found in lib/midori/request.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 send has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Confirmed

          def send(msg)
            output = []
            payload_length = []
            if msg.size < 126
              payload_length << msg.size
        Severity: Minor
        Found in lib/midori/websocket.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 listen has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def listen
            Fiber.schedule do
              until @socket.closed?
                receive_data(@socket)
                if !@buffer.empty?
        Severity: Minor
        Found in lib/midori/connection.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

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

          def set(option, value = (not_set = true), read_only = false)
            raise ArgumentError if not_set
        
            setter = proc { |val| set option, val }
            getter = proc { value }
        Severity: Minor
        Found in lib/midori/core_ext/configurable.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

        TODO found
        Confirmed

            # TODO: implement envents by standard
        Severity: Minor
        Found in lib/midori/eventsource.rb by fixme
        Severity
        Category
        Status
        Source
        Language