Skip to content

fix(architecture-analyzers): 拆分静态组合根分析器降低认知复杂度 - #977

Merged
AlianBlank merged 1 commit into
mainfrom
feature/auto-server-source-worker-run-12782-20261103T0000
Nov 3, 2026
Merged

AlianBlank merged 1 commit into
mainfrom
feature/auto-server-source-worker-run-12782-20261103T0000

Conversation

@AlianBlank

@AlianBlank AlianBlank commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes GFX-1207
Closes #968

Summary by CodeRabbit

  • 重构
    • 调整了架构检查的组织方式,使静态装配状态与组合调用的检查分开处理。
    • 保持现有诊断条件和报告行为不变;此项调整不会改变用户可见功能。

SonarCloud S3776 CRITICAL:StaticCompositionRootAnalyzer.Initialize
认知复杂度 48 超阈值 15。等价拆分为七个私有静态辅助方法
(装配状态面注册/候选判定/成员上报/类型提取/reason 文案、
组合入口面注册/目标方法判定),Initialize 仅保留类型解析、
全空守卫与两路注册;符号面与操作面守卫不共享辅助方法,
注册条件与顺序、豁免集合、reason 文案、上报位置逐字不变,
公共 API 零变化。等价性经 38 例差分测试与既有 5 例回归验证。

Linear: GFX-1207
@linear-code

linear-code Bot commented Nov 3, 2026

Copy link
Copy Markdown

GFX-1207

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73a3f924-0ff3-4484-9c3a-2d3b6eb258a9
Commits

Reviewing files that changed from the base of the PR and between 17b8abb and 6307f9f.

Files selected for processing: 1
  • GameFrameX.Architecture.Analyzers/Analyzers/Architecture/StaticCompositionRootAnalyzer.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

分析器将静态装配状态检测和 Compose 调用检测拆分为独立注册及辅助方法。静态类型筛选、成员类型判定和组合入口判定仍使用原有诊断条件。

Changes: 静态组合根分析器重构

层 / 文件 摘要
静态装配状态检测
GameFrameX.Architecture.Analyzers/Analyzers/Architecture/StaticCompositionRootAnalyzer.cs
Initialize 注册静态类型分析。分析器筛选可报告的静态类型,并检查字段和属性。成员类型为 CapabilityRuntime 或 CapabilityHost 时报告对应诊断。
Compose 调用检测
GameFrameX.Architecture.Analyzers/Analyzers/Architecture/StaticCompositionRootAnalyzer.cs
分析器注册调用检查。目标方法为 CapabilityComposition.Compose,且调用方为符合条件的静态类型时,报告诊断。

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to 6307f

No merge-blocking behavior change is identified. The requested quality workflow and Sonar verification are not reported.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix(architecture-analyzers): 拆分静态组合根分析器降低认知复杂度”描述了本次变更的主要内容:将 StaticCompositionRootAnalyzer.Initialize 拆分为多个辅助方法,以降低认知复杂度。原始摘要与目标均确认此重构是核心变更,并且公共 API 与诊断条件保持不变。标题与变更集相符,符合通过条件。
Linked Issues check Passed [#968] 编码要求:将 StaticCompositionRootAnalyzer.Initialize 的圈复杂度从 48 降至 15 以内。已核对 head 版本:Initialize 仅保留三个条件分支(编译对象空值检查、compositionType 空值检查)。原逻辑拆分为 RegisterStaticAssemblyStateAnalysis、IsReportableStaticT…
Out of Scope Changes check Passed 全部代码变更仅位于 GameFrameX.Architecture.Analyzers/Analyzers/Architecture/StaticCompositionRootAnalyzer.cs。变更内容是对 Initialize 中同一逻辑的结构拆分,并为新增私有辅助方法补充 XML 文档注释。这些变更直接服务于 #968 的复杂度整改目标,不涉及其他文件或其他功能。未发现与 #968 无关…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

[#968] 编码要求:将 StaticCompositionRootAnalyzer.Initialize 的圈复杂度从 48 降至 15 以内。已核对 head 版本:Initialize 仅保留三个条件分支(编译对象空值检查、compositionType 空值检查)。原逻辑拆分为 RegisterStaticAssemblyStateAnalysis、IsReportableStaticType、ReportStaticAssemblyStateMembers、GetDeclaredMemberType、DescribeAssemblyStateMemberType、RegisterComposeEntryAnalysis、IsCapabilityCompositionEntryPoint 等私有静态辅助方法。各辅助方法的分支数量少,单方法复杂度明显低于 15。公开 API 未变化:仅新增 private static 成员,类声明和 Initialize 签名保持不变。诊断 ID GFX0022、Rule 描述、报告位置(member.Locations[0] 与 invocation.Syntax)和 reason 文案均与 base 版本一致。注册顺序保持不变:先注册符号分析,compositionType 为空时返回,再注册调用分析。重写中未发现条件变化。非编码要求(重新运行质量工作流、在 Sonar 中确认问题键不再出现)不属于本次判定范围,且仓库证据不包含其运行结果。

Full details: Out of Scope Changes check

Explanation

全部代码变更仅位于 GameFrameX.Architecture.Analyzers/Analyzers/Architecture/StaticCompositionRootAnalyzer.cs。变更内容是对 Initialize 中同一逻辑的结构拆分,并为新增私有辅助方法补充 XML 文档注释。这些变更直接服务于 #968 的复杂度整改目标,不涉及其他文件或其他功能。未发现与 #968 无关的行为修改。PR 摘要中提到的 38 项差分测试和 5 项回归测试不在本次审查的代码证据范围内,本判定不依赖这些测试。

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 1 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@AlianBlank
AlianBlank merged commit 6a7219d into main Nov 3, 2026
4 checks passed
@AlianBlank
AlianBlank deleted the feature/auto-server-source-worker-run-12782-20261103T0000 branch November 3, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1 [Sonar] Fix GameFrameX.Architecture.Analyzers/Analyzers/Architecture/StaticCompositionRootAnalyzer.cs (1 issue)

1 participant