prebid/Prebid.js

View on GitHub
src/auction.js

Summary

Maintainability
F
4 days
Test Coverage

File auction.js has 681 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Module for auction instances.
 *
 * In Prebid 0.x, $$PREBID_GLOBAL$$ had _bidsRequested and _bidsReceived as public properties.
 * Starting 1.0, Prebid will support concurrent auctions. Each auction instance will store private properties, bidsRequested and bidsReceived.
Severity: Major
Found in src/auction.js - About 1 day to fix

    Function newAuction has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

    export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, auctionId, ortb2Fragments, metrics}) {
      metrics = useMetrics(metrics);
      const _adUnits = adUnits;
      const _labels = labels;
      const _adUnitCodes = adUnitCodes;
    Severity: Minor
    Found in src/auction.js - About 7 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 addBidderRequestsCallback has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function addBidderRequestsCallback(bidRequests) {
        bidRequests.forEach(bidRequest => {
          addBidRequests(bidRequest);
        });
    
    
    Severity: Major
    Found in src/auction.js - About 2 hrs to fix

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

      const _storeInCache = (batch) => {
        store(batch.map(entry => entry.bidResponse), function (error, cacheIds) {
          cacheIds.forEach((cacheId, i) => {
            const { auctionInstance, bidResponse, afterBidAdded } = batch[i];
            if (error) {
      Severity: Minor
      Found in src/auction.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 executeCallback has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function executeCallback(timedOut) {
          if (!timedOut) {
            clearTimeout(_timeoutTimer);
          } else {
            events.emit(EVENTS.AUCTION_TIMEOUT, getProperties());
      Severity: Minor
      Found in src/auction.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

            if (
              ((typeof bidderSettings.suppressEmptyKeys !== 'undefined' && bidderSettings.suppressEmptyKeys === true) ||
                key === TARGETING_KEYS.DEAL || key === TARGETING_KEYS.ACAT || key === TARGETING_KEYS.DSP || key === TARGETING_KEYS.CRID) && // hb_deal & hb_acat are suppressed automatically if not set
              (
                isEmptyStr(value) ||
        Severity: Critical
        Found in src/auction.js - About 1 hr to fix

          Function setKeys has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function setKeys(keyValues, bidderSettings, custBidObj, bidReq) {
            var targeting = bidderSettings[JSON_MAPPING.ADSERVER_TARGETING];
            custBidObj.size = custBidObj.getSize();
          
            (targeting || []).forEach(function (kvPair) {
          Severity: Minor
          Found in src/auction.js - About 1 hr to fix

            Function auctionCallbacks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            export function auctionCallbacks(auctionDone, auctionInstance, {index = auctionManager.index} = {}) {
              let outstandingBidsAdded = 0;
              let allAdapterCalledDone = false;
              let bidderRequestsDone = new Set();
              let bidResponseMap = {};
            Severity: Minor
            Found in src/auction.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 run has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  run: () => {
                    startAuctionTimer();
            
                    _auctionStatus = AUCTION_IN_PROGRESS;
            
            
            Severity: Minor
            Found in src/auction.js - About 1 hr to fix

              Function tryAddVideoBid has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function tryAddVideoBid(auctionInstance, bidResponse, afterBidAdded, {index = auctionManager.index} = {}) {
                let addBid = true;
              
                const videoMediaType = deepAccess(
                  index.getMediaTypes({
              Severity: Minor
              Found in src/auction.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 getStandardBidderSettings has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getStandardBidderSettings(mediaType, bidderCode) {
                const standardSettings = Object.assign({}, bidderSettings.settingsFor(null));
                if (!standardSettings[JSON_MAPPING.ADSERVER_TARGETING]) {
                  standardSettings[JSON_MAPPING.ADSERVER_TARGETING] = defaultAdserverTargeting();
                }
              Severity: Minor
              Found in src/auction.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 getPriceByGranularity has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export const getPriceByGranularity = (granularity) => {
                return (bid) => {
                  const bidGranularity = granularity || getPriceGranularity(bid);
                  if (bidGranularity === GRANULARITY_OPTIONS.AUTO) {
                    return bid.pbAg;
              Severity: Minor
              Found in src/auction.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 getMediaTypeGranularity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getMediaTypeGranularity(mediaType, mediaTypes, mediaTypePriceGranularity) {
                if (mediaType && mediaTypePriceGranularity) {
                  if (FEATURES.VIDEO && mediaType === VIDEO) {
                    const context = deepAccess(mediaTypes, `${VIDEO}.context`, 'instream');
                    if (mediaTypePriceGranularity[`${VIDEO}-${context}`]) {
              Severity: Minor
              Found in src/auction.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 bid.pbHg;
              Severity: Major
              Found in src/auction.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return bid.pbCg;
                Severity: Major
                Found in src/auction.js - About 30 mins to fix

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

                      return {
                        auctionId: _auctionId,
                        timestamp: _auctionStart,
                        auctionEnd: _auctionEnd,
                        auctionStatus: _auctionStatus,
                  Severity: Major
                  Found in src/auction.js and 1 other location - About 2 hrs to fix
                  src/config.js on lines 528..544

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

                  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

                    batchTimeout = typeof cacheConfig.cache.batchTimeout === 'number' && cacheConfig.cache.batchTimeout > 0
                      ? cacheConfig.cache.batchTimeout
                      : 0;
                  Severity: Minor
                  Found in src/auction.js and 1 other location - About 50 mins to fix
                  src/auction.js on lines 605..607

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

                  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

                    batchSize = typeof cacheConfig.cache.batchSize === 'number' && cacheConfig.cache.batchSize > 0
                      ? cacheConfig.cache.batchSize
                      : 1;
                  Severity: Minor
                  Found in src/auction.js and 1 other location - About 50 mins to fix
                  src/auction.js on lines 608..610

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

                  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