Repository navigation
fix(architecture-analyzers): 拆分静态组合根分析器降低认知复杂度 - #977
Conversation
SonarCloud S3776 CRITICAL:StaticCompositionRootAnalyzer.Initialize 认知复杂度 48 超阈值 15。等价拆分为七个私有静态辅助方法 (装配状态面注册/候选判定/成员上报/类型提取/reason 文案、 组合入口面注册/目标方法判定),Initialize 仅保留类型解析、 全空守卫与两路注册;符号面与操作面守卫不共享辅助方法, 注册条件与顺序、豁免集合、reason 文案、上报位置逐字不变, 公共 API 零变化。等价性经 38 例差分测试与既有 5 例回归验证。 Linear: GFX-1207
|
No actionable comments were generated in the recent review.
|
| 层 / 文件 | 摘要 |
|---|---|
静态装配状态检测 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
- GameFrameX/GameFrameX.Server.Source#962:该 PR 新增同一分析器及 GFX0022 规则;本 PR 修改该分析器的
Initialize实现。
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: 
5
-
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.
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
|



Fixes GFX-1207
Closes #968
Summary by CodeRabbit