TryGhost/Ghost

View on GitHub
ghost/member-attribution/lib/ReferrerTranslator.js

Summary

Maintainability
C
1 day
Test Coverage

Function getReferrerDetails has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    getReferrerDetails(history) {
        // Empty history will return null as it means script is not loaded
        if (history.length === 0) {
            return {
                referrerSource: null,
Severity: Minor
Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 3 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 getReferrerDetails has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    getReferrerDetails(history) {
        // Empty history will return null as it means script is not loaded
        if (history.length === 0) {
            return {
                referrerSource: null,
Severity: Major
Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

                if (referrerSource) {
                    const urlData = referrerUrl ? this.getDataFromUrl(referrerUrl) : null;
                    const knownSource = Object.values(knownReferrers).find(referrer => referrer.source.toLowerCase() === referrerSource.toLowerCase());
                    return {
                        referrerSource: knownSource?.source || referrerSource,
    Severity: Major
    Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 40 mins to fix

      Avoid too many return statements within this function.
      Open

                          return {
                              referrerSource: urlData?.source ?? null,
                              referrerMedium: urlData?.medium ?? null,
                              referrerUrl: referrerUrl?.hostname ?? null
                          };
      Severity: Major
      Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return {
                            referrerSource: referrerUrl?.hostname ?? null,
                            referrerMedium: null,
                            referrerUrl: referrerUrl?.hostname ?? null
                        };
        Severity: Major
        Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return {
                      referrerSource: 'Direct',
                      referrerMedium: null,
                      referrerUrl: null
                  };
          Severity: Major
          Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return {
                                referrerSource: knownSource?.source || referrerSource,
                                referrerMedium: knownSource?.medium || referrerMedium || urlData?.medium || null,
                                referrerUrl: referrerUrl?.hostname ?? null
                            };
            Severity: Major
            Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status