prebid/Prebid.js

View on GitHub
modules/adpod.js

Summary

Maintainability
F
4 days
Test Coverage

File adpod.js has 459 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * This module houses the functionality to evaluate and process adpod adunits/bids.  Specifically there are several hooked functions,
 * that either supplement the base function (ie to check something additional or unique to adpod objects) or to replace the base function
 * entirely when appropriate.
 *
Severity: Minor
Found in modules/adpod.js - About 7 hrs to fix

    Function checkAdUnitSetupHook has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    export function checkAdUnitSetupHook(fn, adUnits) {
      let goodAdUnits = adUnits.filter(adUnit => {
        let mediaTypes = deepAccess(adUnit, 'mediaTypes');
        let videoConfig = deepAccess(mediaTypes, 'video');
        if (videoConfig && videoConfig.context === ADPOD) {
    Severity: Minor
    Found in modules/adpod.js - About 3 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

    Function checkVideoBidSetupHook has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    export function checkVideoBidSetupHook(fn, bid, adUnit, videoMediaType, context) {
      if (context === ADPOD) {
        let result = true;
        let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion');
        if (brandCategoryExclusion && !deepAccess(bid, 'meta.primaryCatId')) {
    Severity: Minor
    Found in modules/adpod.js - About 3 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

    Consider simplifying this complex logical expression.
    Open

        if (videoConfig && videoConfig.context === ADPOD) {
          // run check to see if other mediaTypes are defined (ie multi-format); reject adUnit if so
          if (Object.keys(mediaTypes).length > 1) {
            logWarn(`Detected more than one mediaType in adUnitCode: ${adUnit.code} while attempting to define an 'adpod' video adUnit.  'adpod' adUnits cannot be mixed with other mediaTypes.  This adUnit will be removed from the auction.`);
            return false;
    Severity: Critical
    Found in modules/adpod.js - About 2 hrs to fix

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

      function createBidCacheRegistry() {
        let registry = {};
      
        function setupRegistrySlot(auctionId) {
          registry[auctionId] = {};
      Severity: Minor
      Found in modules/adpod.js - About 1 hr to fix

        Function checkAdUnitSetupHook has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function checkAdUnitSetupHook(fn, adUnits) {
          let goodAdUnits = adUnits.filter(adUnit => {
            let mediaTypes = deepAccess(adUnit, 'mediaTypes');
            let videoConfig = deepAccess(mediaTypes, 'video');
            if (videoConfig && videoConfig.context === ADPOD) {
        Severity: Minor
        Found in modules/adpod.js - About 1 hr to fix

          Function goodAdUnits has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            let goodAdUnits = adUnits.filter(adUnit => {
              let mediaTypes = deepAccess(adUnit, 'mediaTypes');
              let videoConfig = deepAccess(mediaTypes, 'video');
              if (videoConfig && videoConfig.context === ADPOD) {
                // run check to see if other mediaTypes are defined (ie multi-format); reject adUnit if so
          Severity: Minor
          Found in modules/adpod.js - About 1 hr to fix

            Function checkVideoBidSetupHook has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function checkVideoBidSetupHook(fn, bid, adUnit, videoMediaType, context) {
              if (context === ADPOD) {
                let result = true;
                let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion');
                if (brandCategoryExclusion && !deepAccess(bid, 'meta.primaryCatId')) {
            Severity: Minor
            Found in modules/adpod.js - About 1 hr to fix

              Function callPrebidCacheHook has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              export function callPrebidCacheHook(fn, auctionInstance, bidResponse, afterBidAdded, videoConfig) {
                if (videoConfig && videoConfig.context === ADPOD) {
                  let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion');
                  let adServerCatId = deepAccess(bidResponse, 'meta.adServerCatId');
                  if (!adServerCatId && brandCategoryExclusion) {
              Severity: Minor
              Found in modules/adpod.js - About 55 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 getTargeting has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getTargeting({ codes, callback } = {}) {
                if (!callback) {
                  logError('No callback function was defined in the getTargeting call.  Aborting getTargeting().');
                  return;
                }
              Severity: Minor
              Found in modules/adpod.js - About 45 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 checkBidDuration has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function checkBidDuration(videoMediaType, bidResponse) {
                const buffer = 2;
                let bidDuration = deepAccess(bidResponse, 'video.durationSeconds');
                let adUnitRanges = videoMediaType.durationRangeSec;
                adUnitRanges.sort((a, b) => a - b); // ensure the ranges are sorted in numeric order
              Severity: Minor
              Found in modules/adpod.js - About 45 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 adpodSetConfig has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export function adpodSetConfig(config) {
                if (config.bidQueueTimeDelay !== undefined) {
                  if (typeof config.bidQueueTimeDelay === 'number' && config.bidQueueTimeDelay > 0) {
                    queueTimeDelay = config.bidQueueTimeDelay;
                  } else {
              Severity: Minor
              Found in modules/adpod.js - About 45 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 checkVideoBidSetupHook has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              export function checkVideoBidSetupHook(fn, bid, adUnit, videoMediaType, context) {
              Severity: Minor
              Found in modules/adpod.js - About 35 mins to fix

                Function callPrebidCacheHook has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                export function callPrebidCacheHook(fn, auctionInstance, bidResponse, afterBidAdded, videoConfig) {
                Severity: Minor
                Found in modules/adpod.js - About 35 mins to fix

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

                  function createBidCacheRegistry() {
                    let registry = {};
                  
                    function setupRegistrySlot(auctionId) {
                      registry[auctionId] = {};
                  Severity: Minor
                  Found in modules/adpod.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

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    if (config.bidQueueSizeLimit !== undefined) {
                      if (typeof config.bidQueueSizeLimit === 'number' && config.bidQueueSizeLimit > 0) {
                        queueSizeLimit = config.bidQueueSizeLimit;
                      } else {
                        logWarn(`Detected invalid value for adpod.bidQueueSizeLimit in setConfig; must be a positive number.  Using default: ${queueSizeLimit}`)
                  Severity: Major
                  Found in modules/adpod.js and 1 other location - About 2 hrs to fix
                  modules/adpod.js on lines 399..405

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 75.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    if (config.bidQueueTimeDelay !== undefined) {
                      if (typeof config.bidQueueTimeDelay === 'number' && config.bidQueueTimeDelay > 0) {
                        queueTimeDelay = config.bidQueueTimeDelay;
                      } else {
                        logWarn(`Detected invalid value for adpod.bidQueueTimeDelay in setConfig; must be a positive number.  Using default: ${queueTimeDelay}`)
                  Severity: Major
                  Found in modules/adpod.js and 1 other location - About 2 hrs to fix
                  modules/adpod.js on lines 407..413

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 75.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                            if (index === arr.length - 1 && adPodTargeting.length > 0) {
                              adPodTargeting.push({
                                [TARGETING_KEY_CACHE_ID]: bid.adserverTargeting[TARGETING_KEY_CACHE_ID]
                              });
                            }
                  Severity: Major
                  Found in modules/adpod.js and 1 other location - About 1 hr to fix
                  modules/adpod.js on lines 565..569

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                              if (index === arr.length - 1 && adPodTargeting.length > 0) {
                                adPodTargeting.push({
                                  [TARGETING_KEY_CACHE_ID]: bid.adserverTargeting[TARGETING_KEY_CACHE_ID]
                                });
                              }
                  Severity: Major
                  Found in modules/adpod.js and 1 other location - About 1 hr to fix
                  modules/adpod.js on lines 527..531

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    if (a.adserverTargeting[TARGETING_KEYS.PRICE_BUCKET] / a.video.durationBucket > b.adserverTargeting[TARGETING_KEYS.PRICE_BUCKET] / b.video.durationBucket) {
                      return -1;
                    }
                  Severity: Minor
                  Found in modules/adpod.js and 1 other location - About 55 mins to fix
                  modules/adpod.js on lines 456..458

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 54.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    if (a.adserverTargeting[TARGETING_KEYS.PRICE_BUCKET] / a.video.durationBucket < b.adserverTargeting[TARGETING_KEYS.PRICE_BUCKET] / b.video.durationBucket) {
                      return 1;
                    }
                  Severity: Minor
                  Found in modules/adpod.js and 1 other location - About 55 mins to fix
                  modules/adpod.js on lines 459..461

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 54.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status