prebid/Prebid.js

View on GitHub
modules/priceFloors.js

Summary

Maintainability
D
2 days
Test Coverage

File priceFloors.js has 593 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import {
  debugTurnedOn,
  deepAccess,
  deepClone,
  deepSetValue,
Severity: Major
Found in modules/priceFloors.js - About 1 day to fix

    Function getFloor has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    export function getFloor(requestParams = {currency: 'USD', mediaType: '*', size: '*'}) {
      let bidRequest = this;
      let floorData = _floorDataForAuction[bidRequest.auctionId];
      if (!floorData || floorData.skipped) return {};
    
    
    Severity: Minor
    Found in modules/priceFloors.js - 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

    Function setImpExtPrebidFloors has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    export function setImpExtPrebidFloors(imp, bidRequest, context) {
      // logic below relates to https://github.com/prebid/Prebid.js/issues/8749 and does the following:
      // 1. check client-side floors (ref bidfloor/bidfloorcur & ortb2Imp floorMin/floorMinCur (if present))
      // 2. set pbs req wide floorMinCur to the first floor currency found when iterating over imp's
      //    (if currency conversion logic present, convert all imp floor values to this currency)
    Severity: Minor
    Found in modules/priceFloors.js - 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

    Function addBidResponseHook has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    export const addBidResponseHook = timedBidResponseHook('priceFloors', function addBidResponseHook(fn, adUnitCode, bid, reject) {
      let floorData = _floorDataForAuction[bid.auctionId];
      // if no floor data then bail
      if (!floorData || !bid || floorData.skipped) {
        return fn.call(this, adUnitCode, bid, reject);
    Severity: Minor
    Found in modules/priceFloors.js - 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

    Function handleSetFloorsConfig has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function handleSetFloorsConfig(config) {
      _floorsConfig = pick(config, [
        'floorMin',
        'enabled', enabled => enabled !== false, // defaults to true
        'auctionDelay', auctionDelay => auctionDelay || 0,
    Severity: Minor
    Found in modules/priceFloors.js - About 1 hr to fix

      Function addBidResponseHook has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const addBidResponseHook = timedBidResponseHook('priceFloors', function addBidResponseHook(fn, adUnitCode, bid, reject) {
        let floorData = _floorDataForAuction[bid.auctionId];
        // if no floor data then bail
        if (!floorData || !bid || floorData.skipped) {
          return fn.call(this, adUnitCode, bid, reject);
      Severity: Minor
      Found in modules/priceFloors.js - About 1 hr to fix

        Function createFloorsDataForAuction has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        export function createFloorsDataForAuction(adUnits, auctionId) {
          let resolvedFloorsData = deepClone(_floorsConfig);
          // if using schema 2 pick a model here:
          if (deepAccess(resolvedFloorsData, 'data.floorsSchemaVersion') === 2) {
            // merge the models specific stuff into the top level data settings (now it looks like floorsSchemaVersion 1!)
        Severity: Minor
        Found in modules/priceFloors.js - 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

        Function updateAdUnitsForAuction has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function updateAdUnitsForAuction(adUnits, floorData, auctionId) {
          const noFloorSignalBiddersArray = getNoFloorSignalBidersArray(floorData)
        
          adUnits.forEach((adUnit) => {
            adUnit.bids.forEach(bid => {
        Severity: Minor
        Found in modules/priceFloors.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

            if (imp.bidfloor != null) {
              let {floorMinCur, floorMin} = context.reqContext.floorMin || {};
          
              if (floorMinCur == null) { floorMinCur = imp.bidfloorcur }
              const ortb2ImpFloorCur = imp.ext?.prebid?.floors?.floorMinCur || imp.ext?.prebid?.floorMinCur || floorMinCur;
          Severity: Major
          Found in modules/priceFloors.js - About 1 hr to fix

            Function generateAndHandleFetch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            export function generateAndHandleFetch(floorEndpoint) {
              // if a fetch url is defined and one is not already occuring, fire it!
              if (floorEndpoint.url && !fetching) {
                // default to GET and we only support GET for now
                let requestMethod = floorEndpoint.method || 'GET';
            Severity: Minor
            Found in modules/priceFloors.js - 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

            Function handleSetFloorsConfig has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            export function handleSetFloorsConfig(config) {
              _floorsConfig = pick(config, [
                'floorMin',
                'enabled', enabled => enabled !== false, // defaults to true
                'auctionDelay', auctionDelay => auctionDelay || 0,
            Severity: Minor
            Found in modules/priceFloors.js - 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

            Function setOrtbImpBidFloor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            export function setOrtbImpBidFloor(imp, bidRequest, context) {
              if (typeof bidRequest.getFloor === 'function') {
                let currency, floor;
                try {
                  ({currency, floor} = bidRequest.getFloor({
            Severity: Minor
            Found in modules/priceFloors.js - 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 function.
            Open

              return fn.call(this, adUnitCode, bid, reject);
            Severity: Major
            Found in modules/priceFloors.js - About 30 mins to fix

              Function normalizeDefault has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export function normalizeDefault(model) {
                if (isNumber(model.default)) {
                  let defaultRule = '*';
                  const numFields = (model.schema?.fields || []).length;
                  if (!numFields) {
              Severity: Minor
              Found in modules/priceFloors.js - 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