返回 Skill 列表
extension
分类: 开发与工程无需 API Key

laravel:complexity-guardrails

保持圈复杂度低;扁平化控制流,提取辅助函数,并优先选择表驱动/策略模式而不是大型switch语句

person作者: jakexiaohubgithub

Complexity Guardrails

Design to keep complexity low from day one.

Targets

  • Cyclomatic complexity per function ≤ 7 (start splitting at 5)
  • Function length ≤ 80 lines (aim for ≤ 30)
  • One responsibility per function; one axis of variation per module

Tactics

  • Use early returns and guard clauses; avoid deep nesting
  • Extract branch bodies into named helpers
  • Replace long if/else/switch with tables (maps) or strategies
  • Separate phases: parse → validate → normalize → act

Signs to refactor now

  • Hard-to-test code paths
  • Repeated conditionals with subtle differences
  • Mixed concerns (IO, validation, transformation) in one method