vorteil/direktiv

View on GitHub
ui/src/design/WorkflowDiagram/utils.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function generateElements has a Cognitive Complexity of 145 (exceeds 5 allowed). Consider refactoring.
Open

export function generateElements(
  getLayoutedElements: (
    incomingEles: (Node | Edge)[],
    orientation: Orientation
  ) => (Node | Edge)[],
Severity: Minor
Found in ui/src/design/WorkflowDiagram/utils.ts - About 2 days 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 generateElements has 184 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function generateElements(
  getLayoutedElements: (
    incomingEles: (Node | Edge)[],
    orientation: Orientation
  ) => (Node | Edge)[],
Severity: Major
Found in ui/src/design/WorkflowDiagram/utils.ts - About 7 hrs to fix

    Function getLayoutedElements has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const getLayoutedElements = (
      incomingEles: (Edge | Node)[],
      orientation: Orientation = "vertical"
    ) => {
      const dagreGraph = new dagre.graphlib.Graph();
    Severity: Minor
    Found in ui/src/design/WorkflowDiagram/utils.ts - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

        if (value.states) {
          for (let i = 0; i < value.states.length; i++) {
            let transitions = false;
            // check if starting element
            if (i === 0) {
      Severity: Major
      Found in ui/src/design/WorkflowDiagram/utils.ts - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                  if (item && item.source === "startNode" && item.target === flow[i]) {
                    // connection between start and first state
                    (newElements[j] as Edge).animated = true;
                  }
        Severity: Major
        Found in ui/src/design/WorkflowDiagram/utils.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (value.states[i]?.conditions[y]?.transition) {
                      newElements.push({
                        id: `${value.states[i]?.id}-${value.states[i]?.conditions[y]?.transition}-${i}-${y}`,
                        source: value.states[i]?.id || "",
                        target: value.states[i]?.conditions[y]?.transition || "",
          Severity: Major
          Found in ui/src/design/WorkflowDiagram/utils.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      if (value.states[i]?.events[j]?.transition) {
                        transitions = true;
                        newElements.push({
                          id: `${value.states[i]?.id}-${value.states[i]?.events[j]?.transition}`,
                          source: value.states[i]?.id || "",
            Severity: Major
            Found in ui/src/design/WorkflowDiagram/utils.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if (item && item.target === flow[i] && item.source === flow[i - 1]) {
                          // connection between two states
                          (newElements[j] as Edge).animated = true;
                        } else if (item && item.id === flow[i]) {
                          if (
              Severity: Major
              Found in ui/src/design/WorkflowDiagram/utils.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if (value.states[i]?.catch[x]?.transition) {
                            transitions = true;
                
                            newElements.push({
                              id: `${value.states[i]?.id}-${value.states[i]?.catch[x]?.transition}`,
                Severity: Major
                Found in ui/src/design/WorkflowDiagram/utils.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if (!flow[i + 1]) {
                              for (let j = 0; j < newElements.length; j++) {
                                if (
                                  (newElements[j] as Edge).source === flow[i] &&
                                  (newElements[j] as Edge).target === "endNode" &&
                  Severity: Major
                  Found in ui/src/design/WorkflowDiagram/utils.ts - About 45 mins to fix

                    Function generateElements has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      getLayoutedElements: (
                        incomingEles: (Node | Edge)[],
                        orientation: Orientation
                      ) => (Node | Edge)[],
                      value: Workflow | null,
                    Severity: Minor
                    Found in ui/src/design/WorkflowDiagram/utils.ts - About 35 mins to fix

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

                            if (value.states[i]?.catch) {
                              for (let x = 0; x < (value.states[i]?.catch?.length || 0); x++) {
                                if (value.states[i]?.catch[x]?.transition) {
                                  transitions = true;
                      
                      
                      Severity: Major
                      Found in ui/src/design/WorkflowDiagram/utils.ts and 1 other location - About 1 day to fix
                      ui/src/design/WorkflowDiagram/utils.ts on lines 107..120

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

                      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 (value.states[i]?.events) {
                              for (let j = 0; j < (value.states[i]?.events.length || 0); j++) {
                                if (value.states[i]?.events[j]?.transition) {
                                  transitions = true;
                                  newElements.push({
                      Severity: Major
                      Found in ui/src/design/WorkflowDiagram/utils.ts and 1 other location - About 1 day to fix
                      ui/src/design/WorkflowDiagram/utils.ts on lines 139..153

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

                      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 (value.states[i]?.transition) {
                              transitions = true;
                      
                              newElements.push({
                                id: `${value.states[i]?.id}-${value.states[i]?.transition}`,
                      Severity: Major
                      Found in ui/src/design/WorkflowDiagram/utils.ts and 1 other location - About 4 hrs to fix
                      ui/src/design/WorkflowDiagram/utils.ts on lines 166..185

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

                      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 (value.states[i]?.defaultTransition) {
                              transitions = true;
                      
                              newElements.push({
                                id: `${value.states[i]?.id}-${value.states[i]?.defaultTransition}`,
                      Severity: Major
                      Found in ui/src/design/WorkflowDiagram/utils.ts and 1 other location - About 4 hrs to fix
                      ui/src/design/WorkflowDiagram/utils.ts on lines 156..185

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

                      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