Class AdvertisementsController
has 36 methods (exceeds 20 allowed). Consider refactoring. Open
class AdvertisementsController < ApplicationController
include Untrackable
protect_from_forgery except: :show
before_action :set_cors_headers
Method set_campaign
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def set_campaign
return nil if device.bot?
return nil unless property&.active? || property&.pending?
return nil if device_small? && property.hide_on_responsive?
return nil if back_pressure?
- Read upRead up
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 11 (exceeds 5 allowed). Consider refactoring. Open
def show
return head(:forbidden) unless valid_referer?
track_event :virtual_impression_initiated
- Read upRead up
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 choose_creative
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def choose_creative(impression_id, campaign)
return nil unless impression_id && campaign
return Creative.active.find_by(id: campaign.creative_ids.first) if campaign.creative_ids.size == 1
split_experiment = Split::ExperimentCatalog.find_or_create(campaign.split_test_name, *campaign.split_alternative_names)
return Creative.active.find_by_split_test_name(split_experiment.winner.name) if split_experiment.winner
- Read upRead up
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_advertisement_variables
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def set_advertisement_variables
@target = params[:target] || "codefund_ad"
return unless @campaign
@creative = choose_creative(@virtual_impression_id, @campaign)
- Read upRead up
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
Avoid too many return
statements within this method. Open
return if property.prohibit_fallback_campaigns?