check-abstract-factory

Audit an implementation of the Abstract Factory pattern, checking family consistency, product hierarchies, completeness of factory methods, and cross-family compatibility.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "check-abstract-factory" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-ece5618c247ccc6b4468d66bd079df4ad6cf58a0e38b2e2e21be7cc7c7ed52b5. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Audit an implementation of the Abstract Factory pattern, checking family consistency, product hierarchies, completeness of factory methods, and cross-family compatibility.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Audits Abstract Factory pattern implementations. Checks family consistency, product hierarchy, factory method completeness, and cross-family compatibility.
Inputs and outputs
```markdown
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
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

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

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

Highlights

  • 触发描述精准完整,明确指向抽象工厂模式审计,边界清晰无歧义
Structure and Standards95/100

Highlights

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

Highlights

  • 提供可执行的 Grep 命令用于实际检测
  • 覆盖多种典型反模式场景,逻辑闭环,具备高可靠性
Evidence Verifiability (mean of the first four)88/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

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

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.