dtaniwaki/e2e-tester

View on GitHub
app/controllers/api/v1/base_controller.rb

Summary

Maintainability
A
45 mins
Test Coverage

Method set_pagination_header has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def set_pagination_header(records, params = request.params)
        links = []
        links << %(<#{url_for(params.merge(page: records.next_page))}>; rel="next") unless records.last_page?
        links << %(<#{url_for(params.merge(page: records.total_pages))}>; rel="last") unless records.last_page?
        links << %(<#{url_for(params.merge(page: 1))}>; rel="first") unless records.first_page?
Severity: Minor
Found in app/controllers/api/v1/base_controller.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

index is not explicitly defined on the controller.
Open

      after_action :verify_authorized, except: :index

This cop checks that methods specified in the filter's only or except options are explicitly defined in the controller.

You can specify methods of superclass or methods added by mixins on the filter, but these confuse developers. If you specify methods where are defined on another controller, you should define the filter in that controller.

Example:

# bad
class LoginController < ApplicationController
  before_action :require_login, only: %i[index settings logout]

  def index
  end
end

# good
class LoginController < ApplicationController
  before_action :require_login, only: %i[index settings logout]

  def index
  end

  def settings
  end

  def logout
  end
end

index is not explicitly defined on the controller.
Open

      after_action :verify_policy_scoped, only: :index

This cop checks that methods specified in the filter's only or except options are explicitly defined in the controller.

You can specify methods of superclass or methods added by mixins on the filter, but these confuse developers. If you specify methods where are defined on another controller, you should define the filter in that controller.

Example:

# bad
class LoginController < ApplicationController
  before_action :require_login, only: %i[index settings logout]

  def index
  end
end

# good
class LoginController < ApplicationController
  before_action :require_login, only: %i[index settings logout]

  def index
  end

  def settings
  end

  def logout
  end
end

There are no issues that match your filters.

Category
Status