TryGhost/Ghost

View on GitHub
ghost/oembed-service/lib/OEmbedService.js

Summary

Maintainability
D
2 days
Test Coverage

Function fetchOembedDataFromUrl has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    async fetchOembedDataFromUrl(url, type, options = {}) {
        try {
            const urlObject = new URL(url);

            // Trimming solves the difference of url validation between `new URL(url)`
Severity: Minor
Found in ghost/oembed-service/lib/OEmbedService.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

File OEmbedService.js has 292 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const logging = require('@tryghost/logging');
const cheerio = require('cheerio');
const _ = require('lodash');
Severity: Minor
Found in ghost/oembed-service/lib/OEmbedService.js - About 3 hrs to fix

    Function fetchOembedDataFromUrl has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        async fetchOembedDataFromUrl(url, type, options = {}) {
            try {
                const urlObject = new URL(url);
    
                // Trimming solves the difference of url validation between `new URL(url)`
    Severity: Major
    Found in ghost/oembed-service/lib/OEmbedService.js - About 2 hrs to fix

      Function fetchBookmarkData has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async fetchBookmarkData(url, html) {
              const gotOpts = {};
      
              if (process.env.NODE_ENV?.startsWith('test')) {
                  gotOpts.retry = 0;
      Severity: Major
      Found in ghost/oembed-service/lib/OEmbedService.js - About 2 hrs to fix

        Function fetchOembedData has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            async fetchOembedData(url, html, cardType) {
                // check for <link rel="alternate" type="application/json+oembed"> element
                let oembedUrl;
                try {
                    oembedUrl = cheerio('link[type="application/json+oembed"]', html).attr('href');
        Severity: Minor
        Found in ghost/oembed-service/lib/OEmbedService.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 fetchOembedData has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async fetchOembedData(url, html, cardType) {
                // check for <link rel="alternate" type="application/json+oembed"> element
                let oembedUrl;
                try {
                    oembedUrl = cheerio('link[type="application/json+oembed"]', html).attr('href');
        Severity: Minor
        Found in ghost/oembed-service/lib/OEmbedService.js - About 1 hr to fix

          Function fetchPageHtml has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async fetchPageHtml(url, options = {}) {
                  // Fetch url and get response as binary buffer to
                  // avoid implicit cast
                  let {headers, body, url: responseUrl} = await this.fetchPage(
                      url,
          Severity: Minor
          Found in ghost/oembed-service/lib/OEmbedService.js - About 1 hr to fix

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

                async fetchBookmarkData(url, html) {
                    const gotOpts = {};
            
                    if (process.env.NODE_ENV?.startsWith('test')) {
                        gotOpts.retry = 0;
            Severity: Minor
            Found in ghost/oembed-service/lib/OEmbedService.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

            Avoid too many return statements within this function.
            Open

                        return this.unknownProvider(url);
            Severity: Major
            Found in ghost/oembed-service/lib/OEmbedService.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return {...bookmark, body, contentType};
              Severity: Major
              Found in ghost/oembed-service/lib/OEmbedService.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                    return this.knownProvider(providerUrl);
                Severity: Major
                Found in ghost/oembed-service/lib/OEmbedService.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return this.unknownProvider(url);
                  Severity: Major
                  Found in ghost/oembed-service/lib/OEmbedService.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return data;
                    Severity: Major
                    Found in ghost/oembed-service/lib/OEmbedService.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return oembed;
                      Severity: Major
                      Found in ghost/oembed-service/lib/OEmbedService.js - About 30 mins to fix

                        There are no issues that match your filters.

                        Category
                        Status