check-abstract-factory

审计抽象工厂模式的实现,检查家族一致性、产品层次结构、工厂方法完整性以及不同产品家族之间的兼容性。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "check-abstract-factory":https://skillpi.com/zh/skills/deepskill-ece5618c247ccc6b4468d66bd079df4ad6cf58a0e38b2e2e21be7cc7c7ed52b5。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

审计抽象工厂模式的实现,检查家族一致性、产品层次结构、工厂方法完整性以及不同产品家族之间的兼容性。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
输入和输出
减记
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: check-abstract-factory
description: Audits Abstract Factory pattern implementations. Checks family consistency, product hierarchy, factory method completeness, and cross-family compatibility.

Abstract Factory Pattern Audit

Analyze PHP code for Abstract Factory pattern compliance — ensuring consistent object families and proper product hierarchies.

Detection Patterns

1. Missing Abstract Factory (Direct Instantiation of Families)

// ANTIPATTERN: Creating related objects without factory
class NotificationService
{
    public function send(string $type, string $message): void
    {
        if ($type === 'email') {
            $transport = new SmtpTransport();      // Family: Email
            $formatter = new HtmlFormatter();       // Family: Email
            $tracker = new EmailOpenTracker();       // Family: Email
        } elseif ($type === 'sms') {
            $transport = new TwilioTransport();     // Family: SMS
            $formatter = new PlainTextFormatter();  // Family: SMS
            $tracker = new SmsDeliveryTracker();    // Family: SMS
        }
    }
}

// CORRECT: Abstract Factory ensures family consistency
interface NotificationFactory
{
    public function createTransport(): TransportInterface;
    public function createFormatter(): FormatterInterface;
    public function createTracker(): TrackerInterface;
}

2. Incomplete Product Family

// ANTIPATTERN: Factory missing products
final readonly class EmailNotificationFactory implements NotificationFactory
{
    public function createTransport(): TransportInterface
    {
        return new SmtpTransport();
    }

    public function createFormatter(): FormatterInterface
    {
        return new HtmlFormatter();
    }

    // MISSING: createTracker() — incomplete family!
}

3. Cross-Family Mixing

// ANTIPATTERN: Products from different families mixed
final readonly class PushNotificationFactory implements NotificationFactory
{
    public function createTransport(): TransportInterface
    {
        return new FirebaseTransport(); // Push family
    }

    public function createFormatter(): FormatterInterface
    {
        return new HtmlFormatter(); // Email family! Wrong!
    }
}

4. No Interface Return Types

// ANTIPATTERN: Factory returns concrete types
class DatabaseFactory
{
    public function createConnection(): MySqlConnection  // Concrete!
    {
        return new MySqlConnection();
    }

    public function createQueryBuilder(): MySqlQueryBuilder  // Concrete!
    {
        return new MySqlQueryBuilder();
    }
}

// CORRECT: Returns interfaces
interface DatabaseFactory
{
    public function createConnection(): ConnectionInterface;
    public function createQueryBuilder(): QueryBuilderInterface;
}

5. Factory Without Interface

// ANTIPATTERN: Concrete factory without abstraction
class PaymentGatewayFactory
{
    public function createProcessor(): StripeProcessor { }
    public function createRefunder(): StripeRefunder { }
}
// Cannot swap to PayPal family!

// CORRECT: Abstract factory interface
interface PaymentGatewayFactory
{
    public function createProcessor(): PaymentProcessorInterface;
    public function createRefunder(): RefundProcessorInterface;
}

final readonly class StripeGatewayFactory implements PaymentGatewayFactory { }
final readonly class PayPalGatewayFactory implements PaymentGatewayFactory { }

Grep Patterns

# Abstract Factory detection
Grep: "interface.*Factory" --glob "**/*.php"
Grep: "AbstractFactory|FactoryInterface" --glob "**/*.php"

# Multiple create methods in one class (potential Abstract Factory)
Grep: "function create[A-Z]" --glob "**/*Factory.php"

# Family instantiation without factory
Grep: "if.*===.*new.*\n.*new.*\n.*new" --glob "**/*.php"

# Type switch creating object families
Grep: "switch.*type|switch.*strategy|switch.*provider" --glob "**/*.php"

# Factory returning concrete types
Grep: "function create.*: [A-Z][a-zA-Z]+[^I](?!nterface)" --glob "**/*Factory.php"

Audit Checklist

Check Severity Description
Factory interface exists 🔴 Critical Each family must have abstract factory
All products defined 🔴 Critical Every family creates all required products
Interface return types 🟠 Major Factory methods return interfaces
No cross-family mixing 🟠 Major Products belong to same family
Family consistency 🟠 Major All factories create compatible products
Single Responsibility 🟡 Minor Factory only creates, no business logic

Correct Implementation

// Product interfaces
interface ButtonInterface
{
    public function render(): string;
}

interface CheckboxInterface
{
    public function render(): string;
}

// Abstract Factory
interface UIComponentFactory
{
    public function createButton(): ButtonInterface;
    public function createCheckbox(): CheckboxInterface;
}

// Concrete Families
final readonly class MaterialUIFactory implements UIComponentFactory
{
    public function createButton(): ButtonInterface
    {
        return new MaterialButton();
    }

    public function createCheckbox(): CheckboxInterface
    {
        return new MaterialCheckbox();
    }
}

final readonly class BootstrapUIFactory implements UIComponentFactory
{
    public function createButton(): ButtonInterface
    {
        return new BootstrapButton();
    }

    public function createCheckbox(): CheckboxInterface
    {
        return new BootstrapCheckbox();
    }
}

Output Format

### Abstract Factory: [Description]

**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`

**Issue:**
[Description of the Abstract Factory violation]

**Impact:**
- Cross-family incompatibility possible
- Cannot swap implementations cleanly
- Violates Open/Closed Principle

**Code:**
```php
// Current code

Fix:

// Abstract Factory refactored

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值78/100

亮点

  • 提供抽象工厂模式的系统性审计能力,覆盖家族一致性、产品层次结构等关键设计模式问题
  • 面向 PHP 开发者,具有明确的技术实用价值和广泛适用性
触发精准92/100

亮点

  • 触发描述精准完整,明确指向抽象工厂模式审计,边界清晰无歧义
结构规范95/100

亮点

  • 文档结构完整,包含检测模式、Grep 命令、审计清单和正确实现示例
  • frontmatter 完整,示例代码丰富,输出格式规范
执行可靠88/100

亮点

  • 提供可执行的 Grep 命令用于实际检测
  • 覆盖多种典型反模式场景,逻辑闭环,具备高可靠性
证据可验 (前四项均值)88/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。