Godzil/Crunchy

View on GitHub
src/episode.ts

Summary

Maintainability
B
4 hrs
Test Coverage

File episode.ts has 420 lines of code (exceeds 250 allowed). Consider refactoring.
Invalid

'use strict';
import cheerio = require('cheerio');
import fs = require('fs');
import mkdirp = require('mkdirp');
import my_request = require('./my_request');
Severity: Minor
Found in src/episode.ts - About 6 hrs to fix

    Function download has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Invalid

    function download(config: IConfig, page: IEpisodePage, player: IEpisodePlayer, done: (err: Error | string, ign: boolean) => void)
    {
      const serieFolder = sanitiseFileName(config.series || page.series);
    
      let fileName = sanitiseFileName(generateName(config, page));
    Severity: Major
    Found in src/episode.ts - About 3 hrs to fix

      Function scrapePage has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Invalid

      function scrapePage(config: IConfig, address: string, done: (err: Error, page?: IEpisodePage) => void)
      {
        const epId = parseInt((address.match(/[0-9]+$/) || ['0'])[0], 10);
      
        if (!epId)
      Severity: Major
      Found in src/episode.ts - About 2 hrs to fix

        Function downloadSubtitle has 67 lines of code (exceeds 25 allowed). Consider refactoring.
        Wontfix

        function downloadSubtitle(config: IConfig, page: IEpisodePage, player: IEpisodePlayer,
                                  filePath: string, done: (err?: Error | string) => void)
        {
          if (page.media !== null)
          {
        Severity: Major
        Found in src/episode.ts - About 2 hrs to fix

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

          function downloadSubtitle(config: IConfig, page: IEpisodePage, player: IEpisodePlayer,
                                    filePath: string, done: (err?: Error | string) => void)
          {
            if (page.media !== null)
            {
          Severity: Minor
          Found in src/episode.ts - 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 scrapePlayer has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Invalid

          function scrapePlayer(config: IConfig, address: string, id: number, done: (err: Error, player?: IEpisodePlayer) => void)
          {
            const url = address.match(/^(https?:\/\/[^\/]+)/);
          
            if (!url)
          Severity: Major
          Found in src/episode.ts - About 2 hrs to fix

            Function download has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Invalid

            function download(config: IConfig, page: IEpisodePage, player: IEpisodePlayer, done: (err: Error | string, ign: boolean) => void)
            {
              const serieFolder = sanitiseFileName(config.series || page.series);
            
              let fileName = sanitiseFileName(generateName(config, page));
            Severity: Minor
            Found in src/episode.ts - 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 downloadVideo has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function downloadVideo(config: IConfig,  page: IEpisodePage, player: IEpisodePlayer,
                                   filePath: string, done: (err: any) => void)
            {
              if (player == null)
              {
            Severity: Minor
            Found in src/episode.ts - About 55 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 deeply nested control flow statements.
            Open

                        if (err)
                        {
                          log.error('An error occured while fetching subtitles...');
                          return done(err);
                        }
            Severity: Major
            Found in src/episode.ts - About 45 mins to fix

              Function downloadVideo has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Invalid

              function downloadVideo(config: IConfig,  page: IEpisodePage, player: IEpisodePlayer,
                                     filePath: string, done: (err: any) => void)
              Severity: Minor
              Found in src/episode.ts - About 35 mins to fix

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

                function downloadSubtitle(config: IConfig, page: IEpisodePage, player: IEpisodePlayer,
                                          filePath: string, done: (err?: Error | string) => void)
                Severity: Minor
                Found in src/episode.ts - About 35 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status