From 2f7a48415bdac4f6a69799b19ae6494bd805b779 Mon Sep 17 00:00:00 2001 From: "Gerla, J. (Justin)" Date: Fri, 14 Nov 2025 11:46:44 +0000 Subject: [PATCH] refactor: removed unnecessary else blocks in orderPhases --- .../visualProgrammingUI/GraphReducer.ts | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/pages/VisProgPage/visualProgrammingUI/GraphReducer.ts b/src/pages/VisProgPage/visualProgrammingUI/GraphReducer.ts index 6a4ee55..3d85216 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/GraphReducer.ts +++ b/src/pages/VisProgPage/visualProgrammingUI/GraphReducer.ts @@ -167,32 +167,29 @@ export function orderPhases(nodes: AppNode[],edges: Edge[]) : OrderedPhases { ) : OrderedPhases => { // get the current phase and the next phases; const currentPhase = phases[currentIndex]; - const nextPhaseNodes = getOutgoers(currentPhase,phaseNodes,edges); - const nextNodes = getOutgoers(currentPhase,nodes, edges); + const nextPhaseNodes = getOutgoers(currentPhase, phaseNodes, edges); + const nextNodes = getOutgoers(currentPhase, nodes, edges); // handles adding of the next phase to the chain, and error handle if an invalid state is received if (nextPhaseNodes.length === 1 && nextNodes.length === 1) { connections.set(currentPhase.id, nextPhaseNodes[0].id); return nextPhase(phases.push(nextPhaseNodes[0] as PhaseNode) - 1, {phaseNodes: phases, connections: connections}); - } else { - // handle erroneous states - if (nextNodes.length === 0){ - throw new Error(`| INVALID PROGRAM | the source handle of "${currentPhase.id}" doesn't have any outgoing connections`); - } else { - if (nextNodes.length > 1) { - throw new Error(`| INVALID PROGRAM | the source handle of "${currentPhase.id}" connects to too many targets`); - } else { - if (nextNodes[0].type === "end"){ - connections.set(currentPhase.id, "end"); - // returns the final output of the function - return { phaseNodes: phases, connections: connections}; - } else { - throw new Error(`| INVALID PROGRAM | the node "${nextNodes[0].id}" that "${currentPhase.id}" connects to is not a phase or end node`); - } - } - } } + // handle erroneous states + if (nextNodes.length === 0) { + throw new Error(`| INVALID PROGRAM | the source handle of "${currentPhase.id}" doesn't have any outgoing connections`); + } + if (nextNodes.length > 1) { + throw new Error(`| INVALID PROGRAM | the source handle of "${currentPhase.id}" connects to too many targets`); + } + if (nextNodes[0].type === "end") { + connections.set(currentPhase.id, "end"); + // returns the final output of the function + return {phaseNodes: phases, connections: connections}; + } + throw new Error(`| INVALID PROGRAM | the node "${nextNodes[0].id}" that "${currentPhase.id}" connects to is not a phase or end node`); } + // initializes the Map describing the connections between phase nodes // we need this Map to make sure we preserve this information, // so we don't need to do checks on the entire set of edges in further stages of the reduction algorithm