prebid/Prebid.js

View on GitHub
src/prebid.js

Summary

Maintainability
F
3 days
Test Coverage

File prebid.js has 587 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/** @module pbjs */

import {getGlobal} from './prebidGlobal.js';
import {
  deepAccess,
Severity: Major
Found in src/prebid.js - About 1 day to fix

    Function requestBids has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    pbjsInstance.requestBids = (function() {
      const delegate = hook('async', function ({ bidsBackHandler, timeout, adUnits, adUnitCodes, labels, auctionId, ttlBuffer, ortb2, metrics, defer } = {}) {
        events.emit(REQUEST_BIDS);
        const cbTimeout = timeout || config.getConfig('bidderTimeout');
        logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments);
    Severity: Minor
    Found in src/prebid.js - About 1 hr to fix

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

      function validateVideoMediaType(adUnit) {
        const validatedAdUnit = deepClone(adUnit);
        const video = validatedAdUnit.mediaTypes.video;
        if (video.playerSize) {
          let tarPlayerSizeLen = (typeof video.playerSize[0] === 'number') ? 2 : 1;
      Severity: Minor
      Found in src/prebid.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 startAuction has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      export const startAuction = hook('async', function ({ bidsBackHandler, timeout: cbTimeout, adUnits, ttlBuffer, adUnitCodes, labels, auctionId, ortb2Fragments, metrics, defer } = {}) {
        const s2sBidders = getS2SBidderSet(config.getConfig('s2sConfig') || []);
        fillAdUnitDefaults(adUnits);
        adUnits = useMetrics(metrics).measureTime('requestBids.validate', () => checkAdUnitSetup(adUnits));
      
      
      Severity: Minor
      Found in src/prebid.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 validateAdUnit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function validateAdUnit(adUnit) {
        const msg = (msg) => `adUnit.code '${adUnit.code}' ${msg}`;
      
        const mediaTypes = adUnit.mediaTypes;
        const bids = adUnit.bids;
      Severity: Minor
      Found in src/prebid.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 validateSizes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function validateSizes(sizes, targLength) {
        let cleanSizes = [];
        if (isArray(sizes) && ((targLength) ? sizes.length === targLength : sizes.length > 0)) {
          // check if an array of arrays or array of numbers
          if (sizes.every(sz => isArrayOfNums(sz, 2))) {
      Severity: Minor
      Found in src/prebid.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 requestBids has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      pbjsInstance.requestBids = (function() {
        const delegate = hook('async', function ({ bidsBackHandler, timeout, adUnits, adUnitCodes, labels, auctionId, ttlBuffer, ortb2, metrics, defer } = {}) {
          events.emit(REQUEST_BIDS);
          const cbTimeout = timeout || config.getConfig('bidderTimeout');
          logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments);
      Severity: Minor
      Found in src/prebid.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 triggerBilling has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      pbjsInstance.triggerBilling = (winningBid) => {
        const bids = fetchReceivedBids(winningBid, 'Improper use of triggerBilling. It requires a bid with at least an adUnitCode or an adId to function.');
        const triggerBillingBid = bids.find(bid => bid.requestId === winningBid.requestId) || bids[0];
      
        if (bids.length > 0 && triggerBillingBid) {
      Severity: Minor
      Found in src/prebid.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

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

      function validateNativeMediaType(adUnit) {
        const validatedAdUnit = deepClone(adUnit);
        const native = validatedAdUnit.mediaTypes.native;
        // if native assets are specified in OpenRTB format, remove legacy assets and print a warn.
        if (native.ortb) {
      Severity: Minor
      Found in src/prebid.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 3 locations. Consider refactoring.
      Open

        if (native.icon && native.icon.sizes && !Array.isArray(native.icon.sizes)) {
          logError('Please use an array of sizes for native.icon.sizes field.  Removing invalid mediaTypes.native.icon.sizes property from request.');
          delete validatedAdUnit.mediaTypes.native.icon.sizes;
        }
      Severity: Major
      Found in src/prebid.js and 2 other locations - About 1 hr to fix
      src/prebid.js on lines 153..156
      src/prebid.js on lines 157..160

      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 73.

      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 3 locations. Consider refactoring.
      Open

        if (native.image && native.image.sizes && !Array.isArray(native.image.sizes)) {
          logError('Please use an array of sizes for native.image.sizes field.  Removing invalid mediaTypes.native.image.sizes property from request.');
          delete validatedAdUnit.mediaTypes.native.image.sizes;
        }
      Severity: Major
      Found in src/prebid.js and 2 other locations - About 1 hr to fix
      src/prebid.js on lines 157..160
      src/prebid.js on lines 161..164

      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 73.

      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 3 locations. Consider refactoring.
      Open

        if (native.image && native.image.aspect_ratios && !Array.isArray(native.image.aspect_ratios)) {
          logError('Please use an array of sizes for native.image.aspect_ratios field.  Removing invalid mediaTypes.native.image.aspect_ratios property from request.');
          delete validatedAdUnit.mediaTypes.native.image.aspect_ratios;
        }
      Severity: Major
      Found in src/prebid.js and 2 other locations - About 1 hr to fix
      src/prebid.js on lines 153..156
      src/prebid.js on lines 161..164

      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 73.

      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

      pbjsInstance.getBidResponsesForAdUnitCode = function (adUnitCode) {
        const bids = auctionManager.getBidsReceived().filter(bid => bid.adUnitCode === adUnitCode);
        return { bids };
      };
      Severity: Major
      Found in src/prebid.js and 1 other location - About 1 hr to fix
      src/prebid.js on lines 365..368

      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 64.

      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

      pbjsInstance.getNoBidsForAdUnitCode = function (adUnitCode) {
        const bids = auctionManager.getNoBids().filter(bid => bid.adUnitCode === adUnitCode);
        return { bids };
      };
      Severity: Major
      Found in src/prebid.js and 1 other location - About 1 hr to fix
      src/prebid.js on lines 388..391

      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 64.

      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

      export const startAuction = hook('async', function ({ bidsBackHandler, timeout: cbTimeout, adUnits, ttlBuffer, adUnitCodes, labels, auctionId, ortb2Fragments, metrics, defer } = {}) {
        const s2sBidders = getS2SBidderSet(config.getConfig('s2sConfig') || []);
        fillAdUnitDefaults(adUnits);
        adUnits = useMetrics(metrics).measureTime('requestBids.validate', () => checkAdUnitSetup(adUnits));
      
      
      Severity: Major
      Found in src/prebid.js and 1 other location - About 1 hr to fix
      src/prebid.js on lines 499..518

      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 58.

      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

        const delegate = hook('async', function ({ bidsBackHandler, timeout, adUnits, adUnitCodes, labels, auctionId, ttlBuffer, ortb2, metrics, defer } = {}) {
          events.emit(REQUEST_BIDS);
          const cbTimeout = timeout || config.getConfig('bidderTimeout');
          logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments);
          if (adUnitCodes && adUnitCodes.length) {
      Severity: Major
      Found in src/prebid.js and 1 other location - About 1 hr to fix
      src/prebid.js on lines 538..629

      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 58.

      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

          const auction = auctionManager.createAuction({
            adUnits,
            adUnitCodes,
            callback: auctionDone,
            cbTimeout,
      Severity: Minor
      Found in src/prebid.js and 1 other location - About 45 mins to fix
      modules/byDataAnalyticsAdapter.js on lines 322..322

      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 50.

      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