oceanprotocol/ocean.js

View on GitHub
src/contracts/NFTFactory.ts

Summary

Maintainability
F
1 wk
Test Coverage
C
79%

File NFTFactory.ts has 439 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { BigNumber, ethers } from 'ethers'
import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
import {
  generateDtName,
  ZERO_ADDRESS,
Severity: Minor
Found in src/contracts/NFTFactory.ts - About 6 hrs to fix

    NftFactory has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class NftFactory extends SmartContractWithAddress {
      getDefaultAbi() {
        return ERC721Factory.abi as AbiItem[]
      }
    
    
    Severity: Minor
    Found in src/contracts/NFTFactory.ts - About 2 hrs to fix

      Function createNFT has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public async createNFT<G extends boolean = false>(
          nftData: NftCreateData,
          estimateGas?: G
        ): Promise<G extends false ? string : BigNumber> {
          if (!nftData.templateIndex) nftData.templateIndex = 1
      Severity: Major
      Found in src/contracts/NFTFactory.ts - About 2 hrs to fix

        Function getErcCreationParams has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private async getErcCreationParams(dtParams: DatatokenCreateParams): Promise<any> {
            let name: string, symbol: string
            // Generate name & symbol if not present
            if (!dtParams.name || !dtParams.symbol) {
              ;({ name, symbol } = generateDtName())
        Severity: Minor
        Found in src/contracts/NFTFactory.ts - About 1 hr to fix

          Function getErcCreationParams has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            private async getErcCreationParams(dtParams: DatatokenCreateParams): Promise<any> {
              let name: string, symbol: string
              // Generate name & symbol if not present
              if (!dtParams.name || !dtParams.symbol) {
                ;({ name, symbol } = generateDtName())
          Severity: Minor
          Found in src/contracts/NFTFactory.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 createNftWithDatatokenWithDispenser has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public async createNftWithDatatokenWithDispenser<G extends boolean = false>(
              nftCreateData: NftCreateData,
              dtParams: DatatokenCreateParams,
              dispenserParams: DispenserCreationParams,
              estimateGas?: G
          Severity: Minor
          Found in src/contracts/NFTFactory.ts - About 1 hr to fix

            Function createNFT has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              public async createNFT<G extends boolean = false>(
                nftData: NftCreateData,
                estimateGas?: G
              ): Promise<G extends false ? string : BigNumber> {
                if (!nftData.templateIndex) nftData.templateIndex = 1
            Severity: Minor
            Found in src/contracts/NFTFactory.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

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

              public async reactivateTokenTemplate<G extends boolean = false>(
                address: string,
                templateIndex: number,
                estimateGas?: G
              ): Promise<ReceiptOrEstimate<G>> {
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 1 other location - About 1 day to fix
            src/contracts/NFTFactory.ts on lines 340..371

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

            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

              public async disableTokenTemplate<G extends boolean = false>(
                address: string,
                templateIndex: number,
                estimateGas?: G
              ): Promise<ReceiptOrEstimate<G>> {
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 1 other location - About 1 day to fix
            src/contracts/NFTFactory.ts on lines 380..411

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

            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

              public async reactivateNFTTemplate<G extends boolean = false>(
                address: string,
                templateIndex: number,
                estimateGas?: G
              ): Promise<ReceiptOrEstimate<G>> {
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 1 other location - About 1 day to fix
            src/contracts/NFTFactory.ts on lines 231..259

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

            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

              public async disableNFTTemplate<G extends boolean = false>(
                address: string,
                templateIndex: number,
                estimateGas?: G
              ): Promise<ReceiptOrEstimate<G>> {
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 1 other location - About 1 day to fix
            src/contracts/NFTFactory.ts on lines 268..298

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

            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

              public async addNFTTemplate<G extends boolean = false>(
                address: string,
                templateAddress: string,
                estimateGas?: G
              ): Promise<ReceiptOrEstimate<G>> {
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 1 other location - About 1 day to fix
            src/contracts/NFTFactory.ts on lines 307..331

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

            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

              public async addTokenTemplate<G extends boolean = false>(
                address: string,
                templateAddress: string,
                estimateGas?: G
              ): Promise<ReceiptOrEstimate<G>> {
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 1 other location - About 1 day to fix
            src/contracts/NFTFactory.ts on lines 199..222

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

            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

              public async checkNFT(nftAddress: string): Promise<String> {
                const confirmAddress = await this.contract.erc721List(nftAddress)
                return confirmAddress
              }
            Severity: Minor
            Found in src/contracts/NFTFactory.ts and 1 other location - About 55 mins to fix
            src/contracts/NFTFactory.ts on lines 177..180

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

              public async checkDatatoken(datatoken: string): Promise<Boolean> {
                const isDeployed = await this.contract.erc20List(datatoken)
                return isDeployed
              }
            Severity: Minor
            Found in src/contracts/NFTFactory.ts and 1 other location - About 55 mins to fix
            src/contracts/NFTFactory.ts on lines 187..190

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

              public async getCurrentNFTCount(): Promise<number> {
                const nftCount = await this.contract.getCurrentNFTCount()
                return nftCount
              }
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 4 other locations - About 30 mins to fix
            src/contracts/FixedRateExchange.ts on lines 138..141
            src/contracts/NFTFactory.ts on lines 113..116
            src/contracts/NFTFactory.ts on lines 131..134
            src/contracts/NFTFactory.ts on lines 140..143

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

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

              public async getCurrentNFTTemplateCount(): Promise<number> {
                const count = await this.contract.getCurrentNFTTemplateCount()
                return count
              }
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 4 other locations - About 30 mins to fix
            src/contracts/FixedRateExchange.ts on lines 138..141
            src/contracts/NFTFactory.ts on lines 104..107
            src/contracts/NFTFactory.ts on lines 113..116
            src/contracts/NFTFactory.ts on lines 140..143

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

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

              public async getCurrentTokenTemplateCount(): Promise<number> {
                const count = await this.contract.getCurrentTemplateCount()
                return count
              }
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 4 other locations - About 30 mins to fix
            src/contracts/FixedRateExchange.ts on lines 138..141
            src/contracts/NFTFactory.ts on lines 104..107
            src/contracts/NFTFactory.ts on lines 113..116
            src/contracts/NFTFactory.ts on lines 131..134

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

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

              public async getCurrentTokenCount(): Promise<number> {
                const tokenCount = await this.contract.getCurrentTokenCount()
                return tokenCount
              }
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 4 other locations - About 30 mins to fix
            src/contracts/FixedRateExchange.ts on lines 138..141
            src/contracts/NFTFactory.ts on lines 104..107
            src/contracts/NFTFactory.ts on lines 131..134
            src/contracts/NFTFactory.ts on lines 140..143

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

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

              public async getOwner(): Promise<string> {
                const owner = await this.contract.owner()
                return owner
              }
            Severity: Major
            Found in src/contracts/NFTFactory.ts and 3 other locations - About 30 mins to fix
            src/contracts/AccessListFactory.ts on lines 100..103
            src/contracts/FixedRateExchange.ts on lines 630..633
            src/contracts/FixedRateExchange.ts on lines 639..642

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

            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