prebid/Prebid.js

View on GitHub
src/native.js

Summary

Maintainability
F
6 days
Test Coverage

File native.js has 638 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import {
  deepAccess,
  deepClone, getDefinedParams,
  insertHtmlIntoIframe,
  isArray,
Severity: Major
Found in src/native.js - About 1 day to fix

    Function toOrtbNativeRequest has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
    Open

    export function toOrtbNativeRequest(legacyNativeAssets) {
      if (!legacyNativeAssets && !isPlainObject(legacyNativeAssets)) {
        logError('Native assets object is empty or not an object: ', legacyNativeAssets);
        return;
      }
    Severity: Minor
    Found in src/native.js - About 1 day 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 fromOrtbNativeRequest has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    export function fromOrtbNativeRequest(openRTBRequest) {
      if (!isOpenRTBBidRequestValid(openRTBRequest)) {
        return;
      }
    
    
    Severity: Minor
    Found in src/native.js - About 4 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 toOrtbNativeRequest has 82 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function toOrtbNativeRequest(legacyNativeAssets) {
      if (!legacyNativeAssets && !isPlainObject(legacyNativeAssets)) {
        logError('Native assets object is empty or not an object: ', legacyNativeAssets);
        return;
      }
    Severity: Major
    Found in src/native.js - About 3 hrs to fix

      Function toLegacyResponse has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      export function toLegacyResponse(ortbResponse, ortbRequest) {
        const legacyResponse = {};
        const requestAssets = ortbRequest?.assets || [];
        legacyResponse.clickUrl = ortbResponse.link.url;
        legacyResponse.privacyLink = ortbResponse.privacy;
      Severity: Minor
      Found in src/native.js - About 2 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 isOpenRTBAssetValid has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      function isOpenRTBAssetValid(asset) {
        if (!isPlainObject(asset)) {
          logError(`asset must be an object. Provided asset: `, asset);
          return false;
        }
      Severity: Minor
      Found in src/native.js - About 2 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 fromOrtbNativeRequest has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function fromOrtbNativeRequest(openRTBRequest) {
        if (!isOpenRTBBidRequestValid(openRTBRequest)) {
          return;
        }
      
      
      Severity: Minor
      Found in src/native.js - About 1 hr to fix

        Function toOrtbNativeResponse has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function toOrtbNativeResponse(legacyResponse, ortbRequest) {
          const ortbResponse = {
            ...legacyPropertiesToOrtbNative(legacyResponse),
            assets: []
          };
        Severity: Minor
        Found in src/native.js - About 1 hr to fix

          Function toLegacyResponse has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function toLegacyResponse(ortbResponse, ortbRequest) {
            const legacyResponse = {};
            const requestAssets = ortbRequest?.assets || [];
            legacyResponse.clickUrl = ortbResponse.link.url;
            legacyResponse.privacyLink = ortbResponse.privacy;
          Severity: Minor
          Found in src/native.js - About 1 hr to fix

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

            export function convertOrtbRequestToProprietaryNative(bidRequests) {
              if (FEATURES.NATIVE) {
                if (!bidRequests || !isArray(bidRequests)) return bidRequests;
                // check if a conversion is needed
                if (!bidRequests.some(bidRequest => (bidRequest?.mediaTypes || {})[NATIVE]?.ortb)) {
            Severity: Minor
            Found in src/native.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 isOpenRTBAssetValid has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function isOpenRTBAssetValid(asset) {
              if (!isPlainObject(asset)) {
                logError(`asset must be an object. Provided asset: `, asset);
                return false;
              }
            Severity: Minor
            Found in src/native.js - About 1 hr to fix

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

              export function legacyPropertiesToOrtbNative(legacyNative) {
                const response = {
                  link: {},
                  eventtrackers: []
                }
              Severity: Minor
              Found in src/native.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                    if (!Array.isArray(asset.video.mimes) || !Array.isArray(asset.video.protocols) ||
                      !isNumber(asset.video.minduration) || !isNumber(asset.video.maxduration)) {
                      logError('video asset is not properly configured');
                      return false;
                    }
                Severity: Major
                Found in src/native.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if (!isArray(asset.aspect_ratios)) {
                            logError("image.aspect_ratios was passed, but it's not a an array:", asset.aspect_ratios);
                          } else if (!asset.aspect_ratios.length) {
                            logError("image.aspect_ratios was passed, but it's empty:", asset.aspect_ratios);
                          } else {
                  Severity: Major
                  Found in src/native.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if (asset.sizes.length !== 2 || !isInteger(asset.sizes[0]) || !isInteger(asset.sizes[1])) {
                              logError('image.sizes was passed, but its value is not an array of integers:', asset.sizes);
                            } else {
                              ortbAsset.img.w = asset.sizes[0];
                              ortbAsset.img.h = asset.sizes[1];
                    Severity: Major
                    Found in src/native.js - About 45 mins to fix

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

                          return true;
                        Severity: Major
                        Found in src/native.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

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

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

                            function gcd(a, b) {
                              while (a && b && a !== b) {
                                if (a > b) {
                                  a = a - b;
                                } else {
                            Severity: Minor
                            Found in src/native.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

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

                                      const aspectRatios = asset.aspect_ratios
                                        .filter((ar) => ar.ratio_width && ar.ratio_height)
                                        .map(ratio => `${ratio.ratio_width}:${ratio.ratio_height}`);
                            Severity: Major
                            Found in src/native.js and 1 other location - About 1 hr to fix
                            modules/pubmaticBidAdapter.js on lines 420..422

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

                            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 (!isNumber(asset.img.w) && !isNumber(asset.img.wmin)) {
                                  logError(`for img asset there must be 'w' or 'wmin' property`);
                                  return false;
                                }
                            Severity: Minor
                            Found in src/native.js and 1 other location - About 55 mins to fix
                            src/native.js on lines 171..174

                            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 (!isNumber(asset.img.h) && !isNumber(asset.img.hmin)) {
                                  logError(`for img asset there must be 'h' or 'hmin' property`);
                                  return false;
                                }
                            Severity: Minor
                            Found in src/native.js and 1 other location - About 55 mins to fix
                            src/native.js on lines 167..170

                            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

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

                                    if (asset.sizes.length !== 2 || !isInteger(asset.sizes[0]) || !isInteger(asset.sizes[1])) {
                                      logError('image.sizes was passed, but its value is not an array of integers:', asset.sizes);
                                    } else {
                                      ortbAsset.img.w = asset.sizes[0];
                                      ortbAsset.img.h = asset.sizes[1];
                            Severity: Minor
                            Found in src/native.js and 1 other location - About 45 mins to fix
                            modules/pubmaticBidAdapter.js on lines 438..446

                            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