gitcoinco/code_fund_ads

View on GitHub
app/controllers/advertisements_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

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
Severity: Minor
Found in app/controllers/advertisements_controller.rb - About 4 hrs to fix

    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?
    Severity: Minor
    Found in app/controllers/advertisements_controller.rb - About 2 hrs 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 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def show
        return head(:forbidden) unless valid_referer?
    
        track_event :virtual_impression_initiated
    
    
    Severity: Minor
    Found in app/controllers/advertisements_controller.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 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
    Severity: Minor
    Found in app/controllers/advertisements_controller.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 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)
    Severity: Minor
    Found in app/controllers/advertisements_controller.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

    Avoid too many return statements within this method.
    Open

        return if property.prohibit_fallback_campaigns?
    Severity: Major
    Found in app/controllers/advertisements_controller.rb - About 30 mins to fix

      There are no issues that match your filters.

      Category
      Status