rimiti/invoice-it

View on GitHub
src/classes/generator.js

Summary

Maintainability
F
3 days
Test Coverage

Generator has 58 functions (exceeds 20 allowed). Consider refactoring.
Wontfix

export default class Generator extends Common {
  constructor(config) {
    super();
    this._recipient = (config.recipient) ? new Recipient(config.recipient) : new Recipient();
    this._emitter = (config.emitter) ? new Emitter(config.emitter) : new Emitter();
Severity: Major
Found in src/classes/generator.js - About 1 day to fix

    File generator.js has 392 lines of code (exceeds 250 allowed). Consider refactoring.
    Wontfix

    import moment from 'moment';
    import pug from 'pug';
    import fs from 'fs';
    import path from 'path';
    import htmlPDF from 'html-pdf';
    Severity: Minor
    Found in src/classes/generator.js - About 5 hrs to fix

      Function _templateConfiguration has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Wontfix

        _templateConfiguration() {
          const template_rows_per_page = 29;
          const templateConfig = {
            rows_in_first_page: (this.article.length > 19) ? template_rows_per_page : 19,
            rows_per_pages: 43,
      Severity: Minor
      Found in src/classes/generator.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 setReferenceFromPattern has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Wontfix

        setReferenceFromPattern(pattern) {
          const tmp = pattern.split('$').slice(1);
          let output = '';
          // eslint-disable-next-line no-restricted-syntax
          for (const item of tmp) {
      Severity: Minor
      Found in src/classes/generator.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 _preCompileCommonTranslations has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Wontfix

        _preCompileCommonTranslations() {
          return {
            logo: this.logo,
            header_date: this.date,
            table_information: i18n.__({phrase: 'table_information', locale: this.lang}),
      Severity: Minor
      Found in src/classes/generator.js - About 1 hr to fix

        Function _templateConfiguration has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Invalid

          _templateConfiguration() {
            const template_rows_per_page = 29;
            const templateConfig = {
              rows_in_first_page: (this.article.length > 19) ? template_rows_per_page : 19,
              rows_per_pages: 43,
        Severity: Minor
        Found in src/classes/generator.js - About 1 hr to fix

          Function _checkArticle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Wontfix

            _checkArticle(article) {
              if (!Object.prototype.hasOwnProperty.call(article, 'description')) throw new Error('Description attribute is missing');
              if (!Object.prototype.hasOwnProperty.call(article, 'tax')) throw new Error('Tax attribute is missing');
              if (!this.isNumeric(article.tax)) throw new Error('Tax attribute have to be a number');
              if (!Object.prototype.hasOwnProperty.call(article, 'price')) throw new Error('Price attribute is missing');
          Severity: Minor
          Found in src/classes/generator.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

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

            getOrder(params = []) {
              const keys = {
                order_header_title: this.getPhrases('order').header_title,
                order_header_subject: this.getPhrases('order').header_subject,
                order_header_reference: this.getPhrases('order').header_reference,
          Severity: Major
          Found in src/classes/generator.js and 1 other location - About 1 day to fix
          src/classes/generator.js on lines 339..362

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

          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

            getInvoice(params = []) {
              const keys = {
                invoice_header_title: this.getPhrases('invoice').header_title,
                invoice_header_subject: this.getPhrases('invoice').header_subject,
                invoice_header_reference: this.getPhrases('invoice').header_reference,
          Severity: Major
          Found in src/classes/generator.js and 1 other location - About 1 day to fix
          src/classes/generator.js on lines 369..392

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

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

            recipient(obj) {
              if (!obj) return this._recipient;
              return this._recipient.hydrate(obj, this._recipient._itemsToHydrate());
            }
          Severity: Minor
          Found in src/classes/generator.js and 1 other location - About 55 mins to fix
          src/classes/generator.js on lines 253..256

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

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

            emitter(obj) {
              if (!obj) return this._emitter;
              return this._emitter.hydrate(obj, this._emitter._itemsToHydrate());
            }
          Severity: Minor
          Found in src/classes/generator.js and 1 other location - About 55 mins to fix
          src/classes/generator.js on lines 243..246

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

          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