agentsclimarketplace

Check abstract factory

Skill dykyi-roman/awesome-claude-code/skills/check-abstract-factory

Audits Abstract Factory pattern implementations. Checks family consistency, product hierarchy, factory method completeness, and cross-family compatibility.From its SKILL.md

Install
npx -y skills add dykyi-roman/awesome-claude-code --skill check-abstract-factory

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

5.9 KB, as published. Nobody here has run it

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

CheckSeverityDescription
Factory interface existsπŸ”΄ CriticalEach family must have abstract factory
All products definedπŸ”΄ CriticalEvery family creates all required products
Interface return types🟠 MajorFactory methods return interfaces
No cross-family mixing🟠 MajorProducts belong to same family
Family consistency🟠 MajorAll factories create compatible products
Single Responsibility🟑 MinorFactory 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

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.