Skip to content

Commit

Permalink
remove flow model changes and apply loop count to rule
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenHalman committed Feb 13, 2025
1 parent f049f3e commit bc44216
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
14 changes: 3 additions & 11 deletions src/main/models/Flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export class Flow {
public elements?: FlowElement[];
public startReference;
public triggerOrder?: number;
public decisions;
public loops;
public description;
public apiVersion;

private flowVariables = ["choices", "constants", "dynamicChoiceSets", "formulas", "variables"];
private flowResources = ["textTemplates", "stages"];
Expand Down Expand Up @@ -64,9 +60,9 @@ export class Flow {
"waits",
];

constructor(flowName: string, data?: any) {
constructor(flowName: string, data?: { Flow: Flow }) {
this.name = flowName;
if(data){
if (data) {
if (data.Flow) {
this.xmldata = data.Flow;
} else this.xmldata = data;
Expand All @@ -83,8 +79,6 @@ export class Flow {
this.start = this.xmldata.start;
this.status = this.xmldata.status;
this.type = this.xmldata.processType;
this.description = this.xmldata.description;
this.apiVersion = this.xmldata.apiVersion;
this.triggerOrder = this.xmldata.triggerOrder;
const allNodes: (FlowVariable | FlowNode | FlowMetadata)[] = [];
for (const nodeType in this.xmldata) {
Expand Down Expand Up @@ -128,8 +122,6 @@ export class Flow {
}
}
this.elements = allNodes;
this.decisions = this.elements.filter((node) => node.subtype === "decisions");
this.loops = this.elements.filter(node => node.subtype === 'loops');
this.startReference = this.findStart();
}

Expand All @@ -145,7 +137,7 @@ export class Flow {
return n.subtype === "start";
})
) {
let startElement = flowElements.find((n) => {
const startElement = flowElements.find((n) => {
return n.subtype === "start";
});
start = startElement.connectors[0]["reference"];
Expand Down
10 changes: 7 additions & 3 deletions src/main/rules/CyclomaticComplexity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ export class CyclomaticComplexity extends RuleCommon implements core.IRuleDefini

// Calculate Cyclomatic Complexity based on the number of decision rules and loops, adding the number of decisions plus 1.
let cyclomaticComplexity = 1;
for (const decision of flow.decisions) {

const flowDecisions = flow.elements.filter((node) => node.subtype === "decisions");
const flowLoops = flow.elements.filter((node) => node.subtype === "loops");

for (const decision of flowDecisions) {
const rules = decision.element["rules"];
if (Array.isArray(rules)) {
cyclomaticComplexity += rules.length + 1;
} else {
cyclomaticComplexity += 1;
}
}
if (flow.loops && flow.loops.length > 0) {
cyclomaticComplexity += flow.loops.length;
if (flowLoops && flowLoops.length > 0) {
cyclomaticComplexity += flowLoops.length;
}

const results: core.ResultDetails[] = [];
Expand Down

0 comments on commit bc44216

Please sign in to comment.