codeprobe-solid
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStandalone Mode
独立模式
If invoked directly (not via the orchestrator), you must first:
- Read for the output contract, execution modes, and constraints.
../codeprobe/shared-preamble.md - Load applicable reference files from based on the project's tech stack.
../codeprobe/references/ - Default to mode unless the user specifies otherwise.
full
如果直接调用(不通过编排器),你必须先完成以下步骤:
- 读取文件,了解输出约定、执行模式和约束条件。
../codeprobe/shared-preamble.md - 根据项目技术栈,加载目录下的适用参考文件。
../codeprobe/references/ - 除非用户另行指定,默认使用完整模式。
full
SOLID Principles Auditor
SOLID原则审计器
Domain Scope
适用领域
This sub-skill detects violations of the five SOLID principles:
- Single Responsibility Principle (SRP) — A class or module should have only one reason to change.
- Open/Closed Principle (OCP) — Software entities should be open for extension but closed for modification.
- Liskov Substitution Principle (LSP) — Subtypes must be substitutable for their base types without altering program correctness.
- Interface Segregation Principle (ISP) — Clients should not be forced to depend on interfaces they do not use.
- Dependency Inversion Principle (DIP) — High-level modules should not depend on low-level modules; both should depend on abstractions.
此子技能用于检测是否违反以下五项SOLID原则:
- 单一职责原则(SRP) —— 一个类或模块应该只有一个引起变化的原因。
- 开闭原则(OCP) —— 软件实体应对扩展开放,对修改关闭。
- 里氏替换原则(LSP) —— 子类必须能够替换其基类,且不影响程序正确性。
- 接口隔离原则(ISP) —— 客户端不应被迫依赖自己不需要的接口。
- 依赖倒置原则(DIP) —— 高层模块不应依赖低层模块,两者都应依赖抽象。
What It Does NOT Flag
不会标记的情况
- Simple DTOs/value objects with multiple fields — having many properties is not an SRP violation when the class represents a single data concept.
- Small scripts and CLIs that don't need dependency injection — proportional design matters.
- Enums used in switches where the enum is stable and closed (e.g., compass directions, days of the week) — OCP applies when variants are likely to grow.
- Framework-generated classes following framework conventions (e.g., Laravel migrations, Django admin classes, Rails ActiveRecord models with standard callbacks).
- Test helper classes that aggregate setup utilities — test infrastructure has different design constraints.
- 包含多字段的简单DTO/值对象 —— 当类代表单一数据概念时,拥有多个属性不属于SRP违规。
- 无需依赖注入的小型脚本与CLI工具 —— 设计需与规模相匹配。
- 用于switch语句的稳定枚举(如方位、星期几)—— 仅当变体可能增加时,OCP才适用。
- 遵循框架约定的框架生成类(如Laravel迁移、Django后台类、带有标准回调的Rails ActiveRecord模型)。
- 聚合设置工具的测试辅助类 —— 测试基础设施有不同的设计约束。
Detection Instructions
检测说明
SRP — Single Responsibility Principle
SRP — 单一职责原则
| ID Prefix | Signal | How to Detect | Severity |
|---|---|---|---|
| Class has 5+ public methods doing unrelated things | Count public methods. If 5+ exist, check whether they cluster around a single responsibility or span multiple concerns (e.g., authentication + email + database). Look for method name prefixes that suggest different domains. | Major |
| Method exceeds 30 LOC doing multiple concerns | Count lines in each method (excluding blank lines and comments). If > 30 LOC, check whether the method handles multiple distinct steps (validation, transformation, persistence, notification) that could be extracted. | Minor |
| Class name is vague | Flag classes named | Minor |
| Constructor takes 5+ dependencies | Count constructor parameters or injected dependencies. 5+ dependencies suggest the class has too many responsibilities. Check whether dependencies serve different domains. | Major |
| ID前缀 | 信号 | 检测方法 | 严重程度 |
|---|---|---|---|
| 类包含5个及以上执行无关操作的公共方法 | 统计公共方法数量。如果有5个及以上,检查这些方法是否围绕单一职责聚合,还是跨越多个关注点(如身份验证+邮件+数据库)。查看方法名称前缀是否暗示不同领域。 | 严重 |
| 方法代码行数超过30行且处理多个关注点 | 统计每个方法的代码行数(排除空行和注释)。如果超过30行,检查该方法是否处理多个可拆分的独立步骤(验证、转换、持久化、通知)。 | 轻微 |
| 类名称模糊 | 标记名为 | 轻微 |
| 构造函数接收5个及以上依赖 | 统计构造函数参数或注入的依赖数量。5个及以上依赖表明类职责过多。检查这些依赖是否服务于不同领域。 | 严重 |
OCP — Open/Closed Principle
OCP — 开闭原则
| ID Prefix | Signal | How to Detect | Severity |
|---|---|---|---|
| Switch/if-else chains on type or status | Look for | Major |
| No extension point where variants are likely to grow | When a switch/if-else on type is found, check whether there is an interface, abstract class, strategy pattern, or plugin mechanism that would allow adding new variants without modifying the existing code. If absent, flag it. | Minor |
| ID前缀 | 信号 | 检测方法 | 严重程度 |
|---|---|---|---|
| 基于类型或状态的switch/if-else链式判断 | 查找基于类型、状态、角色或类别字段的 | 严重 |
| 变体可能增加但无扩展点 | 当发现基于类型的switch/if-else判断时,检查是否存在接口、抽象类、策略模式或插件机制,允许在不修改现有代码的情况下添加新变体。如果不存在,则标记为违规。 | 轻微 |
LSP — Liskov Substitution Principle
LSP — 里氏替换原则
| ID Prefix | Signal | How to Detect | Severity |
|---|---|---|---|
| Subclass overrides method but changes semantics | Check overridden methods: does the subclass return a fundamentally different type, change the meaning of the return value, or produce side effects the parent does not? Compare method signatures and doc comments. | Major |
| Subclass throws exception parent doesn't declare | Look for overridden methods that throw exceptions not present in the parent's throws clause or documented contract. In dynamic languages, look for | Major |
| Subclass ignores or no-ops parent behavior | Look for overridden methods with empty bodies, | Minor |
| | Search for | Major |
| ID前缀 | 信号 | 检测方法 | 严重程度 |
|---|---|---|---|
| 子类重写方法但改变语义 | 检查重写的方法:子类是否返回完全不同的类型、改变返回值的含义,或产生父类没有的副作用?对比方法签名和文档注释。 | 严重 |
| 子类抛出父类未声明的异常 | 查找重写方法中抛出的、未在父类throws声明或文档契约中提及的异常。在动态语言中,查找父类方法不抛出但子类重写方法中使用 | 严重 |
| 子类忽略或空实现父类行为 | 查找重写方法中包含空方法体、 | 轻微 |
| 多态调用后进行instanceof/类型检查 | 查找对应多态使用的对象进行 | 严重 |
ISP — Interface Segregation Principle
ISP — 接口隔离原则
| ID Prefix | Signal | How to Detect | Severity |
|---|---|---|---|
| Interface has 8+ methods | Count methods declared in each interface/abstract class/protocol. If 8+, the interface is likely too broad. Check whether the methods cluster into distinct groups. | Minor |
| Class implements interface but leaves methods empty or throwing | Look for interface implementations where one or more methods are empty, return null, throw | Major |
| Multiple unrelated method groups in one interface | Analyze the interface's methods: do they fall into 2+ distinct responsibility groups (e.g., read operations + write operations + notification methods)? If so, the interface should be split. | Major |
| ID前缀 | 信号 | 检测方法 | 严重程度 |
|---|---|---|---|
| 接口包含8个及以上方法 | 统计每个接口/抽象类/协议中声明的方法数量。如果超过8个,该接口可能过于宽泛。检查方法是否可划分为不同的组。 | 轻微 |
| 类实现接口但部分方法为空或抛出异常 | 查找接口实现中存在一个或多个空方法、返回null、抛出 | 严重 |
| 单个接口包含多个无关方法组 | 分析接口的方法:是否可分为2个及以上独立的职责组(如读取操作+写入操作+通知方法)?如果是,该接口应拆分。 | 严重 |
DIP — Dependency Inversion Principle
DIP — 依赖倒置原则
| ID Prefix | Signal | How to Detect | Severity |
|---|---|---|---|
| | Search for direct instantiation ( | Major |
| High-level module imports from infrastructure layer directly | Check import statements: does a domain/business logic module import directly from database drivers, HTTP clients, file system libraries, or third-party SDKs without an abstraction layer? Look for patterns like | Major |
| No constructor injection — static method calls to concrete dependencies | Look for static method calls like | Minor |
| ID前缀 | 信号 | 检测方法 | 严重程度 |
|---|---|---|---|
| 业务逻辑中直接实例化 | 查找业务逻辑方法中直接实例化基础设施或服务类的代码( | 严重 |
| 高层模块直接导入基础设施层代码 | 检查导入语句:领域/业务逻辑模块是否直接导入数据库驱动、HTTP客户端、文件系统库或第三方SDK,而没有通过抽象层?查找类似 | 严重 |
| 未使用构造函数注入——直接调用具体依赖的静态方法 | 查找业务逻辑中类似 | 轻微 |
ID Prefixes & Fix Prompt Examples
ID前缀与修复提示示例
- — Single Responsibility Principle violations
SRP- - — Open/Closed Principle violations
OCP- - — Liskov Substitution Principle violations
LSP- - — Interface Segregation Principle violations
ISP- - — Dependency Inversion Principle violations
DIP-
Number findings sequentially within each prefix: , , , etc.
SRP-001SRP-002OCP-001- —— 单一职责原则违规
SRP- - —— 开闭原则违规
OCP- - —— 里氏替换原则违规
LSP- - —— 接口隔离原则违规
ISP- - —— 依赖倒置原则违规
DIP-
每个前缀下的发现按顺序编号:、、等。
SRP-001SRP-002OCP-001Fix Prompt Examples
修复提示示例
- "Refactor : extract payment logic (lines 45-78) into a new
src/OrderService.phpclass. InjectPaymentServicevia constructor intoPaymentService. Move methodsOrderService,calculateTotal(), andapplyDiscount()to the new class."processPayment() - "Replace the switch on in
$type(lines 30-65) with a Strategy pattern: create aNotificationSenderinterface with aNotificationChannelmethod. Createsend(Message $message),EmailChannel, andSmsChannelimplementations. Use aPushChannelto resolve the correct channel by type."NotificationChannelFactory - "In , replace
UserRepository.phpat line 23 with constructor injection: add anew MySqlConnection()parameter to the constructor and use it instead of the concrete instantiation."DatabaseConnectionInterface $connection
- "重构:将支付逻辑(第45-78行)提取到新的
src/OrderService.php类中。通过构造函数将PaymentService注入PaymentService。将OrderService、calculateTotal()和applyDiscount()方法移至新类。"processPayment() - "将中基于
NotificationSender的switch语句(第30-65行)替换为策略模式:创建带有$type方法的send(Message $message)接口。实现NotificationChannel、EmailChannel和SmsChannel类。使用PushChannel根据类型解析对应的渠道。"NotificationChannelFactory - "在中,将第23行的
UserRepository.php替换为构造函数注入:为构造函数添加new MySqlConnection()参数,并使用该参数替代具体实例化。"DatabaseConnectionInterface $connection