prebid/Prebid.js

View on GitHub
src/adapters/bidderFactory.js

Summary

Maintainability
F
3 days
Test Coverage

Function newBidder has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

export function newBidder(spec) {
  return Object.assign(new Adapter(spec.code), {
    getSpec: function() {
      return Object.freeze(Object.assign({}, spec));
    },
Severity: Minor
Found in src/adapters/bidderFactory.js - About 5 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

File bidderFactory.js has 395 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Adapter from '../adapter.js';
import adapterManager from '../adapterManager.js';
import {config} from '../config.js';
import {createBid} from '../bidfactory.js';
import {userSync} from '../userSync.js';
Severity: Minor
Found in src/adapters/bidderFactory.js - About 5 hrs to fix

    Function newBidder has 108 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function newBidder(spec) {
      return Object.assign(new Adapter(spec.code), {
        getSpec: function() {
          return Object.freeze(Object.assign({}, spec));
        },
    Severity: Major
    Found in src/adapters/bidderFactory.js - About 4 hrs to fix

      Function callBids has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          callBids: function(bidderRequest, addBidResponse, done, ajax, onTimelyResponse, configEnabledCallback) {
            if (!Array.isArray(bidderRequest.bids)) {
              return;
            }
            const tidGuard = guardTids(bidderRequest.bidderCode);
      Severity: Major
      Found in src/adapters/bidderFactory.js - About 3 hrs to fix

        Function onSuccess has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            const onSuccess = wrapCallback(function(response, responseObj) {
              networkDone();
              try {
                response = JSON.parse(response);
              } catch (e) { /* response might not be JSON... that's ok. */ }
        Severity: Minor
        Found in src/adapters/bidderFactory.js - About 1 hr to fix

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

          export const registerSyncInner = hook('async', function(spec, responses, gdprConsent, uspConsent, gppConsent) {
            const aliasSyncEnabled = config.getConfig('userSync.aliasSyncEnabled');
            if (spec.getUserSyncs && (aliasSyncEnabled || !adapterManager.aliasRegistry[spec.code])) {
              let filterConfig = config.getConfig('userSync.filterSettings');
              let syncs = spec.getUserSyncs({
          Severity: Minor
          Found in src/adapters/bidderFactory.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 guardTids has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function guardTids(bidderCode) {
            if (isActivityAllowed(ACTIVITY_TRANSMIT_TID, activityParams(MODULE_TYPE_BIDDER, bidderCode))) {
              return {
                bidRequest: (br) => br,
                bidderRequest: (br) => br
          Severity: Minor
          Found in src/adapters/bidderFactory.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

              if (spec.getUserSyncs && (aliasSyncEnabled || !adapterManager.aliasRegistry[spec.code])) {
                let filterConfig = config.getConfig('userSync.filterSettings');
                let syncs = spec.getUserSyncs({
                  iframeEnabled: !!(filterConfig && (filterConfig.iframe || filterConfig.all)),
                  pixelEnabled: !!(filterConfig && (filterConfig.image || filterConfig.all)),
            Severity: Major
            Found in src/adapters/bidderFactory.js - About 1 hr to fix

              Function processBidderRequests has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              export const processBidderRequests = hook('sync', function (spec, bids, bidderRequest, ajax, wrapCallback, {onRequest, onResponse, onPaapi, onError, onBid, onCompletion}) {
              Severity: Minor
              Found in src/adapters/bidderFactory.js - About 45 mins to fix

                Function callBids has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    callBids: function(bidderRequest, addBidResponse, done, ajax, onTimelyResponse, configEnabledCallback) {
                Severity: Minor
                Found in src/adapters/bidderFactory.js - About 45 mins to fix

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

                  export const registerSyncInner = hook('async', function(spec, responses, gdprConsent, uspConsent, gppConsent) {
                  Severity: Minor
                  Found in src/adapters/bidderFactory.js - About 35 mins to fix

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

                    function validBidSize(adUnitCode, bid, {index = auctionManager.index} = {}) {
                      if ((bid.width || parseInt(bid.width, 10) === 0) && (bid.height || parseInt(bid.height, 10) === 0)) {
                        bid.width = parseInt(bid.width, 10);
                        bid.height = parseInt(bid.height, 10);
                        return true;
                    Severity: Minor
                    Found in src/adapters/bidderFactory.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 true;
                    Severity: Major
                    Found in src/adapters/bidderFactory.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return false;
                      Severity: Major
                      Found in src/adapters/bidderFactory.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return false;
                        Severity: Major
                        Found in src/adapters/bidderFactory.js - About 30 mins to fix

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

                          export function isValid(adUnitCode, bid, {index = auctionManager.index} = {}) {
                            function hasValidKeys() {
                              let bidKeys = Object.keys(bid);
                              return COMMON_BID_RESPONSE_KEYS.every(key => includes(bidKeys, key) && !includes([undefined, null], bid[key]));
                            }
                          Severity: Minor
                          Found in src/adapters/bidderFactory.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 guardTids has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          export function guardTids(bidderCode) {
                            if (isActivityAllowed(ACTIVITY_TRANSMIT_TID, activityParams(MODULE_TYPE_BIDDER, bidderCode))) {
                              return {
                                bidRequest: (br) => br,
                                bidderRequest: (br) => br
                          Severity: Minor
                          Found in src/adapters/bidderFactory.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

                                alternateBiddersList = isArray(alternateBiddersList) ? alternateBiddersList.map(val => val.trim().toLowerCase()).filter(val => !!val).filter(uniques) : alternateBiddersList;
                          Severity: Minor
                          Found in src/adapters/bidderFactory.js and 1 other location - About 50 mins to fix
                          modules/pubmaticBidAdapter.js on lines 1175..1175

                          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