title: Cyclomatic complexity for index is too high
body: <p>I have index action in my Controller:</p>
  
  <pre><code>def index
    authenticate_admin!
    @users = User.paginate(per_page: 25, page: params[:page])
    if params[:list_type].to_i == 2 # =&gt; Pending mentors
      @users = @users.where(documents: { is_verified: 0 }, user_type: 0, profile_status: 1)
    elsif params[:list_type].to_i == 1 # =&gt; approved listing
      @users = @users.where(documents: { is_verified: 1 }, user_type: 0) if params[:user_type].to_i.zero? # =&gt; Mentor
      @users = @users.where(user_type: 1) if params[:user_type].to_i == 1 # =&gt; mentee
    end
    @users = @users.where('full_name LIKE ?', "%#{params[:search]}%") if params[:search].present?
    @users = if params[:sort].to_i == 1
      @users.order(full_name: :asc)
    else
      @users.order(id: :desc)
    end
  
    @users = @users.profession.where(id: params[:profession_ids]) if params[:profession_ids].present?
    @users = @users.call('age &gt;= ?', params[:from_date]) if params[:from_date].present?
    @users = @users.call('age &lt;= ?', params[:to_date]) if params[:to_date].present?
    @users = @users.where(gender: params[:gender]) if params[:gender].present?
    @users = @users.includes(:document)
  end
  </code></pre>
  
  <p>but when I run <code>Rubocop</code> to check if my code has any <code>offense</code>.
  then it returns me two errors.</p>
  
  <pre><code>app/controllers/users_controller.rb:5:3: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for index is too high. [11/6]
    def index ...
    ^^^^^^^^^
  app/controllers/users_controller.rb:5:3: C: Metrics/PerceivedComplexity: Perceived complexity for index is too high. [13/7]
    def index ...
    ^^^^^^^^^
  </code></pre>
  
  <p>So, I divide my index action to multiple actions like:</p>
  
  <pre><code>def index
    authenticate_admin!
    @users = User.paginate(per_page: 25, page: params[:page])
    if params[:list_type].to_i == 2 # =&gt; Pending mentors
      @users = @users.where(documents: { is_verified: 0 }, user_type: 0, profile_status: 1)
    elsif params[:list_type].to_i == 1 # =&gt; approved listing
      @users = @users.where(documents: { is_verified: 1 }, user_type: 0) if params[:user_type].to_i.zero? # =&gt; Mentor
      @users = @users.where(user_type: 1) if params[:user_type].to_i == 1 # =&gt; mentee
    end
  
    search
  end
  
  def search
    @users = @users.where('full_name LIKE ?', "%#{params[:search]}%") if params[:search].present?
    @users = if params[:sort].to_i == 1
      @users.order(full_name: :asc)
    else
      @users.order(id: :desc)
    end
  
    apply_filter
  end
  
  def apply_filter
    @users = @users.profession.where(id: params[:profession_ids]) if params[:profession_ids].present?
    @users = @users.call('age &gt;= ?', params[:from_date]) if params[:from_date].present?
    @users = @users.call('age &lt;= ?', params[:to_date]) if params[:to_date].present?
    @users = @users.where(gender: params[:gender]) if params[:gender].present?
    @users = @users.includes(:document)
  end
  </code></pre>
  
  <p>Is this the right way to implement code like this or is there anything else i can do to refine my coding structure?</p>