File sirdataRtdProvider.js
has 533 lines of code (exceeds 250 allowed). Consider refactoring. Open
/**
* This module adds Sirdata provider to the real time data module
* and now supports Seller Defined Audience
* The {@link module:modules/realTimeData} module is required
* The module will fetch segments (user-centric) and categories (page-centric) from Sirdata server
Function getSegmentsAndCategories
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
export function getSegmentsAndCategories(reqBidsConfigObj, onDone, moduleConfig, userConsent) {
logInfo(LOG_PREFIX, 'get Segments And Categories');
const adUnits = (reqBidsConfigObj && reqBidsConfigObj.adUnits) || getGlobal().adUnits;
if (!adUnits) {
logInfo(LOG_PREFIX, 'no ad unit, RTD processing is useless');
- Read upRead up
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 getSegAndCatsArray
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
export function getSegAndCatsArray(data, minScore, pid) {
let sirdataData = { segments: [], categories: [], categories_score: {} };
minScore = typeof minScore === 'number' ? minScore : 30;
const { cattaxid, segtaxid, segments } = data;
const contextualCategories = data.contextual_categories || {};
- Read upRead up
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 (hasDeviceAccess() && !userConsent.coppa && (isEmpty(userConsent.usp) || userConsent.usp === -1 || (userConsent.usp[0] === '1' && (userConsent.usp[1] !== 'N' && userConsent.usp[2] !== 'Y'))) && (!gdprApplies || (deepAccess(userConsent, 'gdpr.vendorData.vendor.consents') && userConsent.gdpr.vendorData.vendor.consents[GVLID] && deepAccess(userConsent, 'gdpr.vendorData.purpose.consents') && userConsent.gdpr.vendorData.purpose.consents[1] && (userConsent.gdpr.vendorData.purpose.consents[2] || userConsent.gdpr.vendorData.purpose.consents[3]) && userConsent.gdpr.vendorData.purpose.consents[4])) && (isEmpty(userConsent.gpp) || userConsent.gpp.gppString) && checkCookieSupport()) {
params.sirdataDomain = 'sddan.com'; // cookie based domain
params.cookieAccessGranted = true; // cookies sent in request
if (gdprApplies && deepAccess(userConsent, 'gdpr.consentString')) {
Function sanitizeContent
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
export function sanitizeContent(content) {
if (content && content.documentElement.textContent && content.documentElement.textContent.length > 500) {
// Reduce size by removing useless content
// Allowed tags
const allowedTags = [
- Read upRead up
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 addSegmentData
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
export function addSegmentData(reqBids, data, adUnits, onDone) {
logInfo(LOG_PREFIX, 'Dispatch Segments And Categories');
const minScore = params.contextualMinRelevancyScore || 30;
let sirdataData = getSegAndCatsArray(data, minScore, '');
- Read upRead up
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 getSegmentsAndCategories
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function getSegmentsAndCategories(reqBidsConfigObj, onDone, moduleConfig, userConsent) {
logInfo(LOG_PREFIX, 'get Segments And Categories');
const adUnits = (reqBidsConfigObj && reqBidsConfigObj.adUnits) || getGlobal().adUnits;
if (!adUnits) {
logInfo(LOG_PREFIX, 'no ad unit, RTD processing is useless');
Function addSegmentData
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function addSegmentData(reqBids, data, adUnits, onDone) {
logInfo(LOG_PREFIX, 'Dispatch Segments And Categories');
const minScore = params.contextualMinRelevancyScore || 30;
let sirdataData = getSegAndCatsArray(data, minScore, '');
Function sanitizeContent
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function sanitizeContent(content) {
if (content && content.documentElement.textContent && content.documentElement.textContent.length > 500) {
// Reduce size by removing useless content
// Allowed tags
const allowedTags = [
Function getSegAndCatsArray
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function getSegAndCatsArray(data, minScore, pid) {
let sirdataData = { segments: [], categories: [], categories_score: {} };
minScore = typeof minScore === 'number' ? minScore : 30;
const { cattaxid, segtaxid, segments } = data;
const contextualCategories = data.contextual_categories || {};
Function applySdaGetSpecificData
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
export function applySdaGetSpecificData(data, sirdataData, biddersParamsExist, reqBids, bid, bidderIndex, adUnit, aliasActualBidder) {
// Apply custom function or return Bidder Specific Data if publisher is ok
if (bidderIndex && params.bidders[bidderIndex]?.customFunction && typeof (params.bidders[bidderIndex]?.customFunction) === 'function') {
return loadCustomFunction(params.bidders[bidderIndex].customFunction, adUnit, sirdataData, data, bid);
}
- Read upRead up
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 pushToOrtb2
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
export function pushToOrtb2(ortb2Fragments, bidder, data, segtaxid, cattaxid) {
try {
if (!isEmpty(data.segments)) {
if (segtaxid) {
setOrtb2Sda(ortb2Fragments, bidder, 'user', data.segments, segtaxid);
- Read upRead up
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 mergeEuidsArrays
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
export function mergeEuidsArrays(euids1, euids2) {
if (isEmpty(euids1)) return euids2;
if (isEmpty(euids2)) return euids1;
const mergedArray = [];
// Helper function to process each array
- Read upRead up
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 applySdaGetSpecificData
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
export function applySdaGetSpecificData(data, sirdataData, biddersParamsExist, reqBids, bid, bidderIndex, adUnit, aliasActualBidder) {
Function postContentForSemanticAnalysis
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export function postContentForSemanticAnalysis(postContentToken, actualUrl) {
if (!postContentToken || !actualUrl) return false;
try {
let content = document.implementation.createHTMLDocument('');
- Read upRead up
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 deeply nested control flow statements. Open
if (pid === '27440' && cattaxid) { // Equativ only
sirdataData.categories.push(`${pid}cc${catId}`);
} else {
sirdataData.categories.push(catId.toString());
sirdataData.categories_score[catId] = value;
Function pushToOrtb2
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
export function pushToOrtb2(ortb2Fragments, bidder, data, segtaxid, cattaxid) {
Function loadCustomFunction
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
export function loadCustomFunction(todo, adUnit, list, data, bid) {
Function setOrtb2Sda
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
export function setOrtb2Sda(ortb2Fragments, bidder, type, segments, segtaxValue) {
Function setCookieOnTopDomain
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
export function setCookieOnTopDomain(key, value, hostname, deleteCookie) {
const subDomains = hostname.split('.');
let expTime = new Date();
expTime.setTime(expTime.getTime() + (deleteCookie ? -1 : 365 * 24 * 60 * 60 * 1000)); // Set expiration time
for (let i = 0; i < subDomains.length; ++i) {
- Read upRead up
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 (!isEmpty(data.categories)) {
if (cattaxid) {
setOrtb2Sda(ortb2Fragments, bidder, 'site', data.categories, cattaxid);
} else {
setOrtb2(ortb2Fragments, bidder, 'site.ext.data', { sd_rtd: { categories: data.categories } });
- Read upRead up
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 69.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!isEmpty(data.segments)) {
if (segtaxid) {
setOrtb2Sda(ortb2Fragments, bidder, 'user', data.segments, segtaxid);
} else {
setOrtb2(ortb2Fragments, bidder, 'user.ext.data', { sd_rtd: { segments: data.segments } });
- Read upRead up
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 69.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (xandrData.segments.length > 0) {
setOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'user.keywords', `sd_rtd=${xandrData.segments.join(',sd_rtd=')}`);
}
- Read upRead up
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 47.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (xandrData.categories.length > 0) {
setOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'site.content.keywords', `sd_rtd=${xandrData.categories.join(',sd_rtd=')}`);
}
- Read upRead up
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 47.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76