scott-wyatt/trailpack-stripe

View on GitHub
api/models/Charge.js

Summary

Maintainability
F
5 days
Test Coverage

Function schema has 204 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static schema (app, Sequelize) {
    let schema = {}
    if (app.config.database.orm === 'waterline' || app.config.database.orm === 'js-data') {
      schema = {
        id: {
Severity: Major
Found in api/models/Charge.js - About 1 day to fix

    File Charge.js has 318 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict'
    
    const Model = require('trails/model')
    
    /**
    Severity: Minor
    Found in api/models/Charge.js - About 3 hrs to fix

      Function config has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        static config (app) {
          let config = {}
      
          if (app && (app.config.database.orm === 'waterline' || app.config.database.orm === 'js-data')) {
            config = {
      Severity: Minor
      Found in api/models/Charge.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 config has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static config (app) {
          let config = {}
      
          if (app && (app.config.database.orm === 'waterline' || app.config.database.orm === 'js-data')) {
            config = {
      Severity: Minor
      Found in api/models/Charge.js - About 1 hr to fix

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

          static schema (app, Sequelize) {
            let schema = {}
            if (app.config.database.orm === 'waterline' || app.config.database.orm === 'js-data') {
              schema = {
                id: {
        Severity: Minor
        Found in api/models/Charge.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

        Identical blocks of code found in 20 locations. Consider refactoring.
        Open

              if (database.models[this.constructor.name.toLowerCase()]) {
                if (database.stores[database.models[this.constructor.name.toLowerCase()].store].dialect == 'postgres') {
                  sJSON = (field) => {
                    return {
                      type: Sequelize.JSON
        Severity: Major
        Found in api/models/Charge.js and 19 other locations - About 6 hrs to fix
        api/models/Applicationfee.js on lines 133..148
        api/models/Applicationfeerefund.js on lines 114..129
        api/models/Bankaccount.js on lines 129..144
        api/models/Bitcoin.js on lines 153..168
        api/models/Card.js on lines 153..168
        api/models/Coupon.js on lines 126..141
        api/models/Customer.js on lines 126..141
        api/models/Discount.js on lines 119..134
        api/models/Event.js on lines 106..121
        api/models/Invoice.js on lines 223..238
        api/models/Invoiceitem.js on lines 140..155
        api/models/Plan.js on lines 123..138
        api/models/Recipient.js on lines 132..147
        api/models/Refund.js on lines 120..135
        api/models/Sku.js on lines 139..154
        api/models/Subscription.js on lines 180..195
        api/models/Token.js on lines 108..123
        api/models/Transfer.js on lines 153..168
        api/models/Transferreversal.js on lines 114..129

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

        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

          stripeChargeFailed(charge, cb) {
            const StripeService = this.app.services.StripeService
            const Charge = this.app.models.Charge
            StripeService.dbStripeEvent('Charge', charge, (err, uCharge) => {
              if (err) {
        Severity: Major
        Found in api/models/Charge.js and 1 other location - About 4 hrs to fix
        api/models/Applicationfee.js on lines 226..238

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

        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 44 locations. Consider refactoring.
        Open

          stripeChargeSucceeded(charge, cb) {
            const StripeService = this.app.services.StripeService
            const Charge = this.app.models.Charge
            StripeService.dbStripeEvent('Charge', charge, (err, uCharge) => {
              if (err) {
        Severity: Major
        Found in api/models/Charge.js and 43 other locations - About 3 hrs to fix
        api/models/Bitcoin.js on lines 248..259
        api/models/Bitcoin.js on lines 267..278
        api/models/Bitcoin.js on lines 286..297
        api/models/Bitcoin.js on lines 305..316
        api/models/Card.js on lines 247..258
        api/models/Card.js on lines 266..277
        api/models/Charge.js on lines 331..342
        api/models/Charge.js on lines 350..361
        api/models/Charge.js on lines 369..380
        api/models/Coupon.js on lines 197..208
        api/models/Customer.js on lines 196..207
        api/models/Customer.js on lines 215..226
        api/models/Discount.js on lines 174..185
        api/models/Discount.js on lines 193..204
        api/models/Dispute.js on lines 216..227
        api/models/Dispute.js on lines 235..246
        api/models/Dispute.js on lines 254..265
        api/models/Dispute.js on lines 273..284
        api/models/Invoice.js on lines 350..361
        api/models/Invoice.js on lines 369..380
        api/models/Invoice.js on lines 388..399
        api/models/Invoice.js on lines 407..418
        api/models/Invoiceitem.js on lines 212..223
        api/models/Invoiceitem.js on lines 231..242
        api/models/Order.js on lines 244..255
        api/models/Order.js on lines 263..274
        api/models/Order.js on lines 282..293
        api/models/Order.js on lines 301..312
        api/models/Plan.js on lines 191..202
        api/models/Plan.js on lines 210..221
        api/models/Product.js on lines 217..228
        api/models/Product.js on lines 236..247
        api/models/Recipient.js on lines 207..218
        api/models/Recipient.js on lines 226..237
        api/models/Sku.js on lines 207..218
        api/models/Sku.js on lines 226..237
        api/models/Subscription.js on lines 262..274
        api/models/Subscription.js on lines 282..294
        api/models/Transfer.js on lines 247..259
        api/models/Transfer.js on lines 267..279
        api/models/Transfer.js on lines 287..299
        api/models/Transfer.js on lines 307..319
        api/models/Transfer.js on lines 327..339

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

        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 44 locations. Consider refactoring.
        Open

          stripeChargeCaptured(charge, cb) {
            const StripeService = this.app.services.StripeService
            const Charge = this.app.models.Charge
            StripeService.dbStripeEvent('Charge', charge, (err, uCharge) => {
              if (err) {
        Severity: Major
        Found in api/models/Charge.js and 43 other locations - About 3 hrs to fix
        api/models/Bitcoin.js on lines 248..259
        api/models/Bitcoin.js on lines 267..278
        api/models/Bitcoin.js on lines 286..297
        api/models/Bitcoin.js on lines 305..316
        api/models/Card.js on lines 247..258
        api/models/Card.js on lines 266..277
        api/models/Charge.js on lines 292..303
        api/models/Charge.js on lines 350..361
        api/models/Charge.js on lines 369..380
        api/models/Coupon.js on lines 197..208
        api/models/Customer.js on lines 196..207
        api/models/Customer.js on lines 215..226
        api/models/Discount.js on lines 174..185
        api/models/Discount.js on lines 193..204
        api/models/Dispute.js on lines 216..227
        api/models/Dispute.js on lines 235..246
        api/models/Dispute.js on lines 254..265
        api/models/Dispute.js on lines 273..284
        api/models/Invoice.js on lines 350..361
        api/models/Invoice.js on lines 369..380
        api/models/Invoice.js on lines 388..399
        api/models/Invoice.js on lines 407..418
        api/models/Invoiceitem.js on lines 212..223
        api/models/Invoiceitem.js on lines 231..242
        api/models/Order.js on lines 244..255
        api/models/Order.js on lines 263..274
        api/models/Order.js on lines 282..293
        api/models/Order.js on lines 301..312
        api/models/Plan.js on lines 191..202
        api/models/Plan.js on lines 210..221
        api/models/Product.js on lines 217..228
        api/models/Product.js on lines 236..247
        api/models/Recipient.js on lines 207..218
        api/models/Recipient.js on lines 226..237
        api/models/Sku.js on lines 207..218
        api/models/Sku.js on lines 226..237
        api/models/Subscription.js on lines 262..274
        api/models/Subscription.js on lines 282..294
        api/models/Transfer.js on lines 247..259
        api/models/Transfer.js on lines 267..279
        api/models/Transfer.js on lines 287..299
        api/models/Transfer.js on lines 307..319
        api/models/Transfer.js on lines 327..339

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

        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 44 locations. Consider refactoring.
        Open

          stripeChargeUpdated(charge, cb) {
            const StripeService = this.app.services.StripeService
            const Charge = this.app.models.Charge
            StripeService.dbStripeEvent('Charge', charge, (err, uCharge) => {
              if (err) {
        Severity: Major
        Found in api/models/Charge.js and 43 other locations - About 3 hrs to fix
        api/models/Bitcoin.js on lines 248..259
        api/models/Bitcoin.js on lines 267..278
        api/models/Bitcoin.js on lines 286..297
        api/models/Bitcoin.js on lines 305..316
        api/models/Card.js on lines 247..258
        api/models/Card.js on lines 266..277
        api/models/Charge.js on lines 292..303
        api/models/Charge.js on lines 331..342
        api/models/Charge.js on lines 369..380
        api/models/Coupon.js on lines 197..208
        api/models/Customer.js on lines 196..207
        api/models/Customer.js on lines 215..226
        api/models/Discount.js on lines 174..185
        api/models/Discount.js on lines 193..204
        api/models/Dispute.js on lines 216..227
        api/models/Dispute.js on lines 235..246
        api/models/Dispute.js on lines 254..265
        api/models/Dispute.js on lines 273..284
        api/models/Invoice.js on lines 350..361
        api/models/Invoice.js on lines 369..380
        api/models/Invoice.js on lines 388..399
        api/models/Invoice.js on lines 407..418
        api/models/Invoiceitem.js on lines 212..223
        api/models/Invoiceitem.js on lines 231..242
        api/models/Order.js on lines 244..255
        api/models/Order.js on lines 263..274
        api/models/Order.js on lines 282..293
        api/models/Order.js on lines 301..312
        api/models/Plan.js on lines 191..202
        api/models/Plan.js on lines 210..221
        api/models/Product.js on lines 217..228
        api/models/Product.js on lines 236..247
        api/models/Recipient.js on lines 207..218
        api/models/Recipient.js on lines 226..237
        api/models/Sku.js on lines 207..218
        api/models/Sku.js on lines 226..237
        api/models/Subscription.js on lines 262..274
        api/models/Subscription.js on lines 282..294
        api/models/Transfer.js on lines 247..259
        api/models/Transfer.js on lines 267..279
        api/models/Transfer.js on lines 287..299
        api/models/Transfer.js on lines 307..319
        api/models/Transfer.js on lines 327..339

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

        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 44 locations. Consider refactoring.
        Open

          stripeChargeRefunded(charge, cb) {
            const StripeService = this.app.services.StripeService
            const Charge = this.app.models.Charge
            StripeService.dbStripeEvent('Charge', charge, (err, uCharge) => {
              if (err) {
        Severity: Major
        Found in api/models/Charge.js and 43 other locations - About 3 hrs to fix
        api/models/Bitcoin.js on lines 248..259
        api/models/Bitcoin.js on lines 267..278
        api/models/Bitcoin.js on lines 286..297
        api/models/Bitcoin.js on lines 305..316
        api/models/Card.js on lines 247..258
        api/models/Card.js on lines 266..277
        api/models/Charge.js on lines 292..303
        api/models/Charge.js on lines 331..342
        api/models/Charge.js on lines 350..361
        api/models/Coupon.js on lines 197..208
        api/models/Customer.js on lines 196..207
        api/models/Customer.js on lines 215..226
        api/models/Discount.js on lines 174..185
        api/models/Discount.js on lines 193..204
        api/models/Dispute.js on lines 216..227
        api/models/Dispute.js on lines 235..246
        api/models/Dispute.js on lines 254..265
        api/models/Dispute.js on lines 273..284
        api/models/Invoice.js on lines 350..361
        api/models/Invoice.js on lines 369..380
        api/models/Invoice.js on lines 388..399
        api/models/Invoice.js on lines 407..418
        api/models/Invoiceitem.js on lines 212..223
        api/models/Invoiceitem.js on lines 231..242
        api/models/Order.js on lines 244..255
        api/models/Order.js on lines 263..274
        api/models/Order.js on lines 282..293
        api/models/Order.js on lines 301..312
        api/models/Plan.js on lines 191..202
        api/models/Plan.js on lines 210..221
        api/models/Product.js on lines 217..228
        api/models/Product.js on lines 236..247
        api/models/Recipient.js on lines 207..218
        api/models/Recipient.js on lines 226..237
        api/models/Sku.js on lines 207..218
        api/models/Sku.js on lines 226..237
        api/models/Subscription.js on lines 262..274
        api/models/Subscription.js on lines 282..294
        api/models/Transfer.js on lines 247..259
        api/models/Transfer.js on lines 267..279
        api/models/Transfer.js on lines 287..299
        api/models/Transfer.js on lines 307..319
        api/models/Transfer.js on lines 327..339

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

        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

        Identical blocks of code found in 24 locations. Consider refactoring.
        Open

              let sJSON = (field) =>{
                return {
                  type: Sequelize.STRING,
                  get: function() {
                    return JSON.parse(this.getDataValue(field))
        Severity: Major
        Found in api/models/Charge.js and 23 other locations - About 2 hrs to fix
        api/models/Applicationfee.js on lines 121..131
        api/models/Applicationfeerefund.js on lines 102..112
        api/models/Bankaccount.js on lines 117..127
        api/models/Bitcoin.js on lines 141..151
        api/models/Card.js on lines 141..151
        api/models/Coupon.js on lines 114..124
        api/models/Customer.js on lines 114..124
        api/models/Discount.js on lines 107..117
        api/models/Dispute.js on lines 126..136
        api/models/Event.js on lines 94..104
        api/models/Invoice.js on lines 211..221
        api/models/Invoiceitem.js on lines 128..138
        api/models/Order.js on lines 143..153
        api/models/Plan.js on lines 111..121
        api/models/Product.js on lines 126..136
        api/models/Recipient.js on lines 120..130
        api/models/Refund.js on lines 108..118
        api/models/Sku.js on lines 127..137
        api/models/Stripeaccount.js on lines 153..163
        api/models/Subscription.js on lines 168..178
        api/models/Token.js on lines 96..106
        api/models/Transfer.js on lines 141..151
        api/models/Transferreversal.js on lines 102..112

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

        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