deliveroo/routemaster-drain

View on GitHub

Showing 10 of 10 total issues

Cyclomatic complexity for fetch_from_cache is too high. [8/6]
Open

      def fetch_from_cache(env)
        return nil unless cache_enabled?(env)
        body, headers, most_recent_index, current_index = currently_cached_content(env)

        unless most_recent_index.to_i == current_index.to_i && body && headers

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 _extract_payload is too high. [7/6]
Open

      def _extract_payload(env)
        data = JSON.parse(env['rack.input'].read).map { |e| Hashie::Mash.new(e) }
        return nil unless data.kind_of?(Array)
        return nil unless data.all? { |e| e.t && e.type && e.topic && e.url }
        return data
Severity: Minor
Found in lib/routemaster/middleware/parse.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 fetch_from_service has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def fetch_from_service(env, event_index)
        @app.call(env).on_complete do |response_env|
          response = response_env.response

          if response.success? && cache_enabled?(env)
Severity: Minor
Found in lib/routemaster/middleware/response_caching.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 fetch_from_cache has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def fetch_from_cache(env)
        return nil unless cache_enabled?(env)
        body, headers, most_recent_index, current_index = currently_cached_content(env)

        unless most_recent_index.to_i == current_index.to_i && body && headers
Severity: Minor
Found in lib/routemaster/middleware/response_caching.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 _extract_payload has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def _extract_payload(env)
        data = JSON.parse(env['rack.input'].read).map { |e| Hashie::Mash.new(e) }
        return nil unless data.kind_of?(Array)
        return nil unless data.all? { |e| e.t && e.type && e.topic && e.url }
        return data
Severity: Minor
Found in lib/routemaster/middleware/parse.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 sweep has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def sweep(limit = 0)
        unswept = []
        while (url = @redis.spop(KEY))
          unswept.push url
          is_swept = !! yield(url)
Severity: Minor
Found in lib/routemaster/dirty/map.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 method_missing has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def method_missing(m, *args, &block)
        method_name = m.to_s
        normalized_method_name = method_name == '_self' ? 'self' : method_name

        if _links.keys.include?(normalized_method_name)
Severity: Minor
Found in lib/routemaster/responses/hateoas_response.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 call has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def call(env)
        env['routemaster.dirty'] = dirty = []

        env.fetch('routemaster.payload', []).each do |event|
          next if event['type'] == 'noop'
Severity: Minor
Found in lib/routemaster/middleware/dirty.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 run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def run(payload)
        events = {} # url -> event

        payload.each do |event|
          known_state = State.get(@redis, event['url'])
Severity: Minor
Found in lib/routemaster/dirty/filter.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

The use of eval is a serious security risk.
Open

      eval(src, nil, file, line)
Severity: Minor
Found in lib/core_ext/forwardable.rb by rubocop

This cop checks for the use of Kernel#eval and Binding#eval.

Example:

# bad

eval(something)
binding.eval(something)
Severity
Category
Status
Source
Language