solid-knowledge
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "solid-knowledge":https://skillpi.com/zh/skills/deepskill-be748b91764ac9e6baeb629e76bddfd6d531e42092d6f82e1d1378a8cb800542。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
面向 PHP 8.4 项目的 SOLID 原则知识库。包含 SRP、OCP、LSP、ISP、DIP 的快速参考,附检测模式、PHP 示例与反模式识别,适用于架构审计和代码质量评审。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: solid-knowledge
description: SOLID principles knowledge base for PHP 8.4 projects. Provides quick reference for SRP, OCP, LSP, ISP, DIP with detection patterns, PHP examples, and antipattern identification. Use for architecture audits and code quality reviews.SOLID Principles Knowledge Base
Overview
SOLID is a set of five design principles for writing maintainable, extensible software.
| Principle | Name | Core Idea |
|---|---|---|
| S | Single Responsibility | One class = one reason to change |
| O | Open/Closed | Open for extension, closed for modification |
| L | Liskov Substitution | Subtypes must be substitutable for base types |
| I | Interface Segregation | Many specific interfaces > one general |
| D | Dependency Inversion | Depend on abstractions, not concretions |
Quick Detection Patterns
SRP Violations
# God classes (>500 lines)
find . -name "*.php" -exec wc -l {} \; | awk '$1 > 500 {print}'
# Classes with "And" in name
grep -rn "class.*And[A-Z]" --include="*.php"
# Classes with >7 dependencies
grep -rn "public function __construct" --include="*.php" -A 20 | grep -E "private|readonly" | wc -l
# Multiple responsibility indicators
grep -rn "class.*Manager\|class.*Handler\|class.*Processor" --include="*.php"
Signs of SRP Violation:
- Class has >500 lines
- Class has >7 dependencies
- Class name contains "And", "Or", "Manager", "Handler"
- Multiple unrelated public methods
- Changes for multiple business reasons
OCP Violations
# Switch on type
grep -rn "switch.*instanceof\|switch.*::class" --include="*.php"
# Type checking conditionals
grep -rn "if.*instanceof\|elseif.*instanceof" --include="*.php"
# Hardcoded type maps
grep -rn "\[.*::class.*=>" --include="*.php"
Signs of OCP Violation:
- Switch statements on object types
- instanceof chains in conditionals
- Adding new types requires modifying existing code
- Hardcoded type-to-behavior mappings
LSP Violations
# Exception in overridden methods
grep -rn "throw.*NotImplemented\|throw.*NotSupported" --include="*.php"
# Empty overrides
grep -rn "public function.*\{[\s]*\}" --include="*.php"
# Type checks in child classes
grep -rn "if.*parent::" --include="*.php"
Signs of LSP Violation:
- Child class throws NotImplementedException
- Child class has empty method overrides
- Parent type check in child class
- Preconditions strengthened in subtype
- Postconditions weakened in subtype
ISP Violations
# Large interfaces (>5 methods)
grep -rn "interface\s" --include="*.php" -A 30 | grep -c "public function"
# Empty interface implementations
grep -rn "// TODO\|// not implemented\|// unused" --include="*.php"
Signs of ISP Violation:
- Interface has >5 methods
- Classes implement interfaces partially
- Unused methods return null/throw
- Interface name too generic ("Service", "Manager")
DIP Violations
# Direct instantiation in constructors
grep -rn "new\s\+[A-Z]" --include="*.php" | grep -v "Exception\|DateTime\|stdClass"
# Static method calls
grep -rn "::[a-z].*(" --include="*.php" | grep -v "self::\|static::\|parent::"
# Concrete class type hints (not interfaces)
grep -rn "function.*([A-Z][a-z]*[A-Z]" --include="*.php"
Signs of DIP Violation:
new ConcreteClass()inside methods- Static calls to concrete classes
- Type hints to concrete classes (not interfaces)
- No constructor injection
PHP 8.4 Patterns
SRP Compliant
<?php
declare(strict_types=1);
// BAD: Multiple responsibilities
final class UserService
{
public function register(UserData $data): User { /* ... */ }
public function sendEmail(User $user): void { /* ... */ }
public function generateReport(User $user): Report { /* ... */ }
}
// GOOD: Single responsibility each
final readonly class RegisterUserHandler
{
public function __construct(
private UserRepository $users,
private EventDispatcher $events,
) {}
public function __invoke(RegisterUserCommand $command): UserId
{
$user = User::register($command->email, $command->password);
$this->users->save($user);
$this->events->dispatch($user->releaseEvents());
return $user->id;
}
}
OCP Compliant
<?php
declare(strict_types=1);
// BAD: Modification required for new types
final class PaymentProcessor
{
public function process(Payment $payment): void
{
match ($payment->type) {
'card' => $this->processCard($payment),
'paypal' => $this->processPaypal($payment),
// Must modify for new payment types
};
}
}
// GOOD: Extension without modification
interface PaymentGateway
{
public function supports(Payment $payment): bool;
public function process(Payment $payment): PaymentResult;
}
final readonly class PaymentProcessor
{
/** @param iterable<PaymentGateway> $gateways */
public function __construct(
private iterable $gateways,
) {}
public function process(Payment $payment): PaymentResult
{
foreach ($this->gateways as $gateway) {
if ($gateway->supports($payment)) {
return $gateway->process($payment);
}
}
throw new UnsupportedPaymentException($payment->type);
}
}
LSP Compliant
<?php
declare(strict_types=1);
// BAD: Violates substitutability
abstract class Bird
{
abstract public function fly(): void;
}
final class Penguin extends Bird
{
public function fly(): void
{
throw new CannotFlyException(); // LSP violation!
}
}
// GOOD: Proper abstraction hierarchy
interface Bird
{
public function move(): void;
}
interface FlyingBird extends Bird
{
public function fly(): void;
}
final readonly class Penguin implements Bird
{
public function move(): void
{
$this->swim();
}
private function swim(): void { /* ... */ }
}
final readonly class Eagle implements FlyingBird
{
public function move(): void
{
$this->fly();
}
public function fly(): void { /* ... */ }
}
ISP Compliant
<?php
declare(strict_types=1);
// BAD: Fat interface
interface UserRepository
{
public function find(UserId $id): ?User;
public function findByEmail(Email $email): ?User;
public function save(User $user): void;
public function delete(User $user): void;
public function findAll(): array;
public function count(): int;
public function export(): string;
public function import(string $data): void;
}
// GOOD: Segregated interfaces
interface UserReader
{
public function find(UserId $id): ?User;
public function findByEmail(Email $email): ?User;
}
interface UserWriter
{
public function save(User $user): void;
public function delete(User $user): void;
}
interface UserExporter
{
public function export(): string;
public function import(string $data): void;
}
// Compose as needed
interface UserRepository extends UserReader, UserWriter {}
DIP Compliant
<?php
declare(strict_types=1);
// BAD: Depends on concretions
final class OrderService
{
public function process(Order $order): void
{
$mailer = new SmtpMailer(); // Concrete dependency
$logger = Logger::getInstance(); // Static dependency
$validator = new OrderValidator(); // Hidden dependency
// ...
}
}
// GOOD: Depends on abstractions
final readonly class OrderService
{
public function __construct(
private OrderRepository $orders,
private Mailer $mailer,
private LoggerInterface $logger,
private OrderValidator $validator,
) {}
public function process(Order $order): void
{
$this->validator->validate($order);
$this->orders->save($order);
$this->mailer->send(new OrderConfirmation($order));
$this->logger->info('Order processed', ['id' => $order->id->value]);
}
}
SOLID & DDD Integration
| SOLID | DDD Application |
|---|---|
| SRP | Aggregates have single consistency boundary |
| OCP | Domain Events enable extension without modification |
| LSP | Value Objects are substitutable (same type = same behavior) |
| ISP | Repository interfaces segregated (Reader/Writer) |
| DIP | Domain depends on Repository interfaces, not implementations |
SOLID & Clean Architecture
| Layer | SOLID Focus |
|---|---|
| Domain | SRP (Entities), LSP (Value Objects), ISP (Repository interfaces) |
| Application | SRP (Use Cases), DIP (Port interfaces) |
| Infrastructure | OCP (Adapters), DIP (Implements ports) |
| Presentation | SRP (Controllers), ISP (API contracts) |
Severity Levels
| Level | Description | Example |
|---|---|---|
| CRITICAL | Fundamental violation affecting entire system | God class, no DI |
| WARNING | Localized violation, should be fixed | instanceof chains |
| INFO | Minor issue, consider refactoring | Interface with 6 methods |
References
See detailed documentation in references/:
srp-patterns.md- Single Responsibility patternsocp-patterns.md- Open/Closed patternslsp-patterns.md- Liskov Substitution patternsisp-patterns.md- Interface Segregation patternsdip-patterns.md- Dependency Inversion patternsantipatterns.md- Common SOLID violations
See assets/report-template.md for audit report format.
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- SOLID 原则知识库为 PHP 开发者提供了实用的架构审计和代码质量评审工具
- 涵盖五大原则的检测模式、PHP 示例和反模式识别,适用性强
亮点
- description 精准描述了 Skill 的核心功能、目标语言和使用场景
- 触发词覆盖完整,边界清晰,无歧义
亮点
- 文档结构清晰,章节划分合理,包含端到端示例
- frontmatter 完整,单文件长度适中,易于阅读
亮点
- 提供的 bash 命令和 PHP 示例语法正确,参数合理
- 覆盖了主要异常情况,工具来源明确,可靠性高
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。