refactor(cli): split EnrichCommand.enrichFromCache to drop cognitive complexity (RAN-41)#73
Merged
Merged
Conversation
… (RAN-41) The 313-line enrichFromCache method scored cognitive complexity 94 on SonarCloud (S3776, allowed 15) when PR #71 (RAN-23) re-classified it as new code. Even small future edits in this file would re-trip the new-code quality gate. Extracted phases into private helpers, preserving exact ordering, side effects, log lines, exit codes, and determinism: - applyGraphDirOverride — --graph option handling - runLinkerPhase — GraphBuilder + cross-file linkers - runClassifierAndEnrichers — layer / lexical / language enrichment - runServiceDetection — ServiceDetector + node/edge merge - bulkLoadIntoNeo4j — top-level Neo4j orchestration - clearGraph — batched DETACH DELETE - bulkLoadNodes — UNWIND CREATE in NODE_BATCH_SIZE batches - createPrimaryIndex — id index + awaitIndexes - createStubNodesForExternalRefs / flushStubBatches / writeStubBatch - buildValidEdgeMaps / toEdgeProps - bulkLoadEdges — UNWIND MATCH/CREATE batches - createSecondaryIndexes — kind/layer/module/path/fulltext indexes - printCompletionSummary - shutdownQuietly — finally-block dbms shutdown - logStepDone — shared "Done in Xms" line Also lifted magic numbers (batch sizes, await timeout, progress interval, stub-merge Cypher) into named constants and replaced fully-qualified references (java.util.HashSet, ServiceDetector, ObjectMapper) with imports for readability. After refactor each method's cognitive complexity is well under 15 (orchestrator at ~1, largest helper at ~11). Verification: - mvn test -Dskip.npm=true → 3395 tests, 0 failures, 0 errors - mvn spotbugs:check → 0 findings - EnrichCommandTest (4) → still green Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Refactor
EnrichCommand.enrichFromCache()from a 313-line method (cognitive complexity 94, S3776 limit 15) into a thin orchestrator + small phase helpers, so any future edit in this file keeps the SonarCloud new-code quality gate green.The S3776 finding was surfaced on PR #71 (RAN-23) when SpotBugs cleanup re-classified
enrichFromCachelines as new code.What changed
enrichFromCache()is now an orchestrator (~10 lines, complexity ~1). Each phase lives in its own private helper, with identical ordering, log lines, exit codes, and side effects:applyGraphDirOverride,runLinkerPhase,runClassifierAndEnrichers,runServiceDetectionbulkLoadIntoNeo4j(top-level Neo4j) →clearGraph,bulkLoadNodes,createPrimaryIndex,createStubNodesForExternalRefs(+flushStubBatches/writeStubBatch),buildValidEdgeMaps/toEdgeProps,bulkLoadEdges,createSecondaryIndexes,printCompletionSummary,shutdownQuietlylogStepDonefor the" Done in Xms"lineNODE_BATCH_SIZE,EDGE_BATCH_SIZE,STUB_BATCH_SIZE,CLEAR_BATCH_SIZE,PROGRESS_REPORT_INTERVAL,INDEX_AWAIT_SECONDS)java.util.*,ServiceDetector,ObjectMapperreferences promoted to importsExceptiontoJsonProcessingExceptionNo behavior change. Determinism preserved (same buffered builder, same flush + flushDeferred sequence, same node/edge ordering).
Verification
mvn test -Dskip.npm=true→ 3395 tests, 0 failures, 0 errors, 31 skippedmvn spotbugs:check→ 0 findingsEnrichCommandTest(4 tests) → greencreateStubNodesForExternalRefs~11)Test plan
EnrichCommand.javareports 0 new S3776 findingsCloses RAN-41.
🤖 Generated with Claude Code