buttercup-pw/buttercup-core

View on GitHub
source/core/VaultSource.ts

Summary

Maintainability
F
3 days
Test Coverage

File VaultSource.ts has 619 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import EventEmitter from "eventemitter3";
import { ChannelQueue } from "@buttercup/channel-queue";
import { Layerr } from "layerr";
import { Vault } from "./Vault.js";
import { Credentials } from "../credentials/Credentials.js";
Severity: Major
Found in source/core/VaultSource.ts - About 1 day to fix

    VaultSource has 38 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class VaultSource extends EventEmitter {
        static STATUS_LOCKED = VaultSourceStatus.Locked;
        static STATUS_PENDING = VaultSourceStatus.Pending;
        static STATUS_UNLOCKED = VaultSourceStatus.Unlocked;
    
    
    Severity: Minor
    Found in source/core/VaultSource.ts - About 5 hrs to fix

      Function unlock has 78 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async unlock(vaultCredentials: Credentials, config: VaultSourceUnlockOptions = {}) {
              if (!Credentials.isCredentials(vaultCredentials)) {
                  throw new Layerr(
                      `Failed unlocking source: Invalid credentials passed to source: ${this.id}`
                  );
      Severity: Major
      Found in source/core/VaultSource.ts - About 3 hrs to fix

        Function changeMasterPassword has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async changeMasterPassword(
                oldPassword: string,
                newPassword: string,
                meta: { [key: string]: any } = {}
            ) {
        Severity: Minor
        Found in source/core/VaultSource.ts - About 1 hr to fix

          Function save has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async save(config: VaultSourceSaveOptions = {}) {
                  const { storeOfflineCopy = true } = config;
                  await this._enqueueStateChange(async () => {
                      if (await this.localDiffersFromRemote()) {
                          await this.mergeFromRemote();
          Severity: Minor
          Found in source/core/VaultSource.ts - About 1 hr to fix

            Function localDiffersFromRemote has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                localDiffersFromRemote(): Promise<boolean> {
                    if (this.status !== VaultSource.STATUS_UNLOCKED) {
                        return Promise.reject(
                            new Layerr(
                                `Failed diffing source: Source not unlocked (${this.status}): ${this.id}`
            Severity: Minor
            Found in source/core/VaultSource.ts - About 1 hr to fix

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

                  async changeMasterPassword(
                      oldPassword: string,
                      newPassword: string,
                      meta: { [key: string]: any } = {}
                  ) {
              Severity: Minor
              Found in source/core/VaultSource.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 lock has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async lock() {
                      if (this.status !== VaultSource.STATUS_UNLOCKED) {
                          throw new Layerr(
                              `Failed locking source: Source in invalid state (${this.status}): ${this.id}`
                          );
              Severity: Minor
              Found in source/core/VaultSource.ts - About 1 hr to fix

                Function update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    async update({ skipDiff = false } = {}) {
                        const didUpdate = await this._enqueueStateChange(
                            () =>
                                (skipDiff ? Promise.resolve(false) : this.localDiffersFromRemote()).then(
                                    (differs) => {
                Severity: Minor
                Found in source/core/VaultSource.ts - About 25 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 2 locations. Consider refactoring.
                Open

                                await this._datasource.save(
                                    this._vault.format.history,
                                    prepareDatasourceCredentials(
                                        this._credentials as Credentials,
                                        this._datasource.type
                Severity: Minor
                Found in source/core/VaultSource.ts and 1 other location - About 55 mins to fix
                source/core/VaultSource.ts on lines 768..774

                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

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

                            await this._datasource.save(
                                this._vault.format.history,
                                prepareDatasourceCredentials(
                                    this._credentials as Credentials,
                                    this._datasource.type
                Severity: Minor
                Found in source/core/VaultSource.ts and 1 other location - About 55 mins to fix
                source/core/VaultSource.ts on lines 590..596

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

                        if (this.status !== VaultSource.STATUS_UNLOCKED) {
                            throw new Layerr(
                                `Failed converting source: Source not unlocked (${this.status}): ${this.id}`
                            );
                        }
                Severity: Minor
                Found in source/core/VaultSource.ts and 2 other locations - About 35 mins to fix
                source/core/VaultSource.ts on lines 473..477
                source/core/VaultSource.ts on lines 653..657

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

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

                        if (this.status !== VaultSource.STATUS_UNLOCKED) {
                            throw new Layerr(
                                `Failed locking source: Source in invalid state (${this.status}): ${this.id}`
                            );
                        }
                Severity: Minor
                Found in source/core/VaultSource.ts and 2 other locations - About 35 mins to fix
                source/core/VaultSource.ts on lines 341..345
                source/core/VaultSource.ts on lines 653..657

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

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

                        if (this.status !== VaultSource.STATUS_LOCKED) {
                            throw new Layerr(
                                `Failed unlocking source: Source in invalid state (${this.status}): ${this.id}`
                            );
                        }
                Severity: Minor
                Found in source/core/VaultSource.ts and 2 other locations - About 35 mins to fix
                source/core/VaultSource.ts on lines 341..345
                source/core/VaultSource.ts on lines 473..477

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

                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