uu-cubitt/graph

View on GitHub
src/Graph.ts

Summary

Maintainability
F
4 days
Test Coverage

Function deserialize has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    public deserialize(jsonObject: Object): GraphInterface {
        let graph = new Graph();
        let models = jsonObject["models"];
        let queue: Collections.Queue<Object> = new Collections.Queue<Object>();
        let inQueue: Common.Dictionary<Boolean> = {};
Severity: Minor
Found in src/Graph.ts - About 5 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

File Graph.ts has 315 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as Common from "cubitt-common";
import * as Collections from "typescript-collections";
import {AbstractElement} from "./AbstractElement";
import {NodeElement} from "./NodeElement";
import {EdgeElement} from "./EdgeElement";
Severity: Minor
Found in src/Graph.ts - About 3 hrs to fix

    Function deserialize has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public deserialize(jsonObject: Object): GraphInterface {
            let graph = new Graph();
            let models = jsonObject["models"];
            let queue: Collections.Queue<Object> = new Collections.Queue<Object>();
            let inQueue: Common.Dictionary<Boolean> = {};
    Severity: Major
    Found in src/Graph.ts - About 2 hrs to fix

      Graph has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class Graph implements GraphInterface {
          private elements: Common.Dictionary<AbstractElement>;
      
          constructor() {
              this.elements = {};
      Severity: Minor
      Found in src/Graph.ts - About 2 hrs to fix

        Function serialize has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public serialize() {
                let graph = {
                    "models": {},
                    "nodes": {},
                    "edges": {},
        Severity: Minor
        Found in src/Graph.ts - About 1 hr to fix

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

              public addModel(id: Common.Guid, type: string, properties: Common.Dictionary<any>, parentId?: Common.Guid) {
                  // Validate GUID
                  /* istanbul ignore if */
                  if (this.hasElement(id)) {
                      throw new Error("An Element with GUID " + id.toString() + " already exists");
          Severity: Minor
          Found in src/Graph.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 addEdge has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public addEdge(id: Common.Guid, type: string, modelId: Common.Guid, startConnectorId: Common.Guid, endConnectorId: Common.Guid, properties: Common.Dictionary<any> = {}) {
                  // Validate GUID
                  /* istanbul ignore if */
                  if (this.hasElement(id)) {
                      throw new Error("An Element with GUID " + id.toString() + " already exists");
          Severity: Minor
          Found in src/Graph.ts - About 1 hr to fix

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

                public addEdge(id: Common.Guid, type: string, modelId: Common.Guid, startConnectorId: Common.Guid, endConnectorId: Common.Guid, properties: Common.Dictionary<any> = {}) {
                    // Validate GUID
                    /* istanbul ignore if */
                    if (this.hasElement(id)) {
                        throw new Error("An Element with GUID " + id.toString() + " already exists");
            Severity: Minor
            Found in src/Graph.ts - 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

            Avoid deeply nested control flow statements.
            Open

                                        for (let connectorId of edge["neighbours"]["connectors"]["parent"]) {
                                            if (inQueue[connectorId] !== true) {
                                                isInQueue = false;
                                            }
                                        }
            Severity: Major
            Found in src/Graph.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          if (isInQueue === true) {
                                              edges.push(edgeId);
                                          }
              Severity: Major
              Found in src/Graph.ts - About 45 mins to fix

                Function deleteElement has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public deleteElement(id: Common.Guid, ofType?: ElementType): void {
                        if (ofType === undefined) {
                            delete this.elements[id.toString()];
                        } else {
                            let elem = this.elements[id.toString()];
                Severity: Minor
                Found in src/Graph.ts - About 35 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

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

                    public serialize() {
                        let graph = {
                            "models": {},
                            "nodes": {},
                            "edges": {},
                Severity: Minor
                Found in src/Graph.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

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

                    public hasModel(id: Common.Guid): boolean {
                        let elem = this.elements[id.toString()];
                        return elem !== undefined && elem.getType() === ElementType.Model;
                    }
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 2 hrs to fix
                src/Graph.ts on lines 56..59
                src/Graph.ts on lines 64..67
                src/Graph.ts on lines 72..75

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

                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 hasNode(id: Common.Guid): boolean {
                        let elem = this.elements[id.toString()];
                        return elem !== undefined && elem.getType() === ElementType.Node;
                    }
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 2 hrs to fix
                src/Graph.ts on lines 48..51
                src/Graph.ts on lines 64..67
                src/Graph.ts on lines 72..75

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

                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 hasConnector(id: Common.Guid): boolean {
                        let elem = this.elements[id.toString()];
                        return elem !== undefined && elem.getType() === ElementType.Connector;
                    }
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 2 hrs to fix
                src/Graph.ts on lines 48..51
                src/Graph.ts on lines 56..59
                src/Graph.ts on lines 72..75

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

                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 hasEdge(id: Common.Guid): boolean {
                        let elem = this.elements[id.toString()];
                        return elem !== undefined && elem.getType() === ElementType.Edge;
                    }
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 2 hrs to fix
                src/Graph.ts on lines 48..51
                src/Graph.ts on lines 56..59
                src/Graph.ts on lines 64..67

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

                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

                                    "connectors": {
                                        "parent": elem.getParentConnectorNeighbours().map(g => g.toString()),
                                        "child": elem.getChildConnectorNeighbours().map(g => g.toString())
                                    }
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 1 hr to fix
                src/Graph.ts on lines 443..446
                src/Graph.ts on lines 447..450
                src/Graph.ts on lines 451..454

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

                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

                                    "nodes": {
                                        "parent": elem.getParentNodeNeighbours().map(g => g.toString()),
                                        "child": elem.getChildNodeNeighbours().map(g => g.toString())
                                    },
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 1 hr to fix
                src/Graph.ts on lines 443..446
                src/Graph.ts on lines 451..454
                src/Graph.ts on lines 455..458

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

                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

                                    "models": {
                                        "parent": elem.getParentModelNeighbours().map(g => g.toString()),
                                        "child": elem.getChildModelNeighbours().map(g => g.toString())
                                    },
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 1 hr to fix
                src/Graph.ts on lines 447..450
                src/Graph.ts on lines 451..454
                src/Graph.ts on lines 455..458

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

                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

                                    "edges": {
                                        "parent": elem.getParentEdgeNeighbours().map(g => g.toString()),
                                        "child": elem.getChildEdgeNeighbours().map(g => g.toString())
                                    },
                Severity: Major
                Found in src/Graph.ts and 3 other locations - About 1 hr to fix
                src/Graph.ts on lines 443..446
                src/Graph.ts on lines 447..450
                src/Graph.ts on lines 455..458

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

                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

                                    } else if (elem["neighbours"]["edges"]["parent"].length > 0) {
                                        graph.addModel(Common.Guid.parse(elem.id), properties["type"], properties, Common.Guid.parse(elem["neighbours"]["edges"]["parent"][0]));
                                    } else {
                                        graph.addModel(Common.Guid.parse(elem.id), properties["type"], properties);
                                    }
                Severity: Major
                Found in src/Graph.ts and 1 other location - About 1 hr to fix
                src/Graph.ts on lines 336..342

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

                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

                                    if (elem["neighbours"]["nodes"]["parent"].length > 0) {
                                        graph.addModel(Common.Guid.parse(elem.id), properties["type"], properties, Common.Guid.parse(elem["neighbours"]["nodes"]["parent"][0]));
                                    } else if (elem["neighbours"]["edges"]["parent"].length > 0) {
                                        graph.addModel(Common.Guid.parse(elem.id), properties["type"], properties, Common.Guid.parse(elem["neighbours"]["edges"]["parent"][0]));
                                    } else {
                Severity: Major
                Found in src/Graph.ts and 1 other location - About 1 hr to fix
                src/Graph.ts on lines 338..342

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

                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