assemblymade/coderwall

View on GitHub
app/controllers/protips_controller.rb

Summary

Maintainability
D
1 day
Test Coverage

Class ProtipsController has 56 methods (exceeds 20 allowed). Consider refactoring.
Open

class ProtipsController < ApplicationController

  before_action :access_required, only: [:new, :create, :edit, :update, :destroy, :me]
  before_action :require_skills_first, only: [:new, :create]
  before_action :lookup_protip, only: %i(show edit update destroy upvote tag flag feature delete_tag)
Severity: Major
Found in app/controllers/protips_controller.rb - About 1 day to fix

    File protips_controller.rb has 429 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ProtipsController < ApplicationController
    
      before_action :access_required, only: [:new, :create, :edit, :update, :destroy, :me]
      before_action :require_skills_first, only: [:new, :create]
      before_action :lookup_protip, only: %i(show edit update destroy upvote tag flag feature delete_tag)
    Severity: Minor
    Found in app/controllers/protips_controller.rb - About 6 hrs to fix

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

        def update
          # strong_parameters will intentionally fail if a key is present but has an empty hash. :(
          update_params = if params[:protip] && params[:protip].keys.present?
                            params.require(:protip).permit(:title, :body, :user_id, :topic_list)
                          else
      Severity: Minor
      Found in app/controllers/protips_controller.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 show has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def show
          show_params = if is_admin?
                          params.permit(:reply_to, :q, :t, :i, :p)
                        else
                          params.permit(:reply_to)
      Severity: Minor
      Found in app/controllers/protips_controller.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 date has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def date
          date_params = params.permit(:date, :query, :page, :per_page)
      
          date = Date.current if date_params[:date].downcase == "today"
          date = Date.current.advance(days: -1) if params[:date].downcase == "yesterday"
      Severity: Minor
      Found in app/controllers/protips_controller.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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          create_params = if params[:protip] && params[:protip].keys.present?
                            params.require(:protip).permit(:title, :body, :user_id, :topic_list)
                          else
                            {}
      Severity: Minor
      Found in app/controllers/protips_controller.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

      There are no issues that match your filters.

      Category
      Status