Skip to content
Back to skills

Acc Create Policy

ASecurity

Generates Policy pattern for PHP 8.5. Creates encapsulated business rules for authorization, validation, and domain constraints. Includes unit tests.

  • 666 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 2, 2026
ai-agentsphp

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add majiayu000/claude-skill-registry --skill acc-create-policy --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Acc Create Policy?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Acc Create Policy
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-acc-create-policy-claude-skill-registry/badge)](https://www.skillsdirectory.com/skills/majiayu000-acc-create-policy-claude-skill-registry)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: acc-create-policy
description: Generates Policy pattern for PHP 8.5. Creates encapsulated business rules for authorization, validation, and domain constraints. Includes unit tests.
---

# Policy Pattern Generator

Creates Policy pattern infrastructure for encapsulating business rules and authorization logic.

## When to Use

| Scenario | Example |
|----------|---------|
| Authorization checks | Can user cancel order? |
| Business rule validation | Is discount applicable? |
| Complex conditions | Multiple rules combined |
| Auditable decisions | Log why access denied |

## Component Characteristics

### PolicyInterface
- Single responsibility rule
- Returns authorization result
- Provides denial reasons

### Policy Implementation
- Encapsulates one business rule
- Stateless evaluation
- Composable with other policies

### PolicyResult
- Success/failure status
- Denial reasons
- Metadata for logging

---

## Generation Process

### Step 1: Generate Shared Components

**Path:** `src/Domain/Shared/Policy/`

1. `PolicyResult.php` — Result value object with and/or composition
2. `CompositionMode.php` — Enum for AllMustPass/AnyMustPass

### Step 2: Generate Policy Interface

**Path:** `src/Domain/{BoundedContext}/Policy/`

1. `{Name}PolicyInterface.php` — Policy contract

### Step 3: Generate Concrete Policies

**Path:** `src/Domain/{BoundedContext}/Policy/`

1. `{Rule1}Policy.php` — First rule implementation
2. `{Rule2}Policy.php` — Second rule implementation
3. `{Name}Policy.php` — Composite policy combining rules

### Step 4: Generate Exception

**Path:** `src/Domain/Shared/Exception/`

1. `PolicyViolationException.php` — Exception with policy context

### Step 5: Generate Tests

1. `{Rule}PolicyTest.php` — Individual rule tests
2. `{Name}PolicyTest.php` — Composite policy tests
3. `PolicyResultTest.php` — Result composition tests

---

## File Placement

| Component | Path |
|-----------|------|
| Policy Interface | `src/Domain/{BoundedContext}/Policy/` |
| Policy Implementation | `src/Domain/{BoundedContext}/Policy/` |
| PolicyResult | `src/Domain/Shared/Policy/` |
| Exception | `src/Domain/Shared/Exception/` |
| Unit Tests | `tests/Unit/Domain/{BoundedContext}/Policy/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| Interface | `{Name}PolicyInterface` | `OrderCancellationPolicyInterface` |
| Implementation | `{Rule}Policy` | `OrderOwnershipPolicy` |
| Composite | `{Name}Policy` | `OrderCancellationPolicy` |
| Result | `PolicyResult` | `PolicyResult` |
| Exception | `PolicyViolationException` | `PolicyViolationException` |
| Test | `{ClassName}Test` | `OrderOwnershipPolicyTest` |

---

## Quick Template Reference

### PolicyInterface

```php
interface {Name}PolicyInterface
{
    public function evaluate({SubjectType} $subject, {ResourceType} $resource): PolicyResult;
    public function getRuleName(): string;
}
```

### PolicyResult

```php
final readonly class PolicyResult
{
    public static function allow(): self;
    public static function deny(string $reason, array $metadata = []): self;
    public function isAllowed(): bool;
    public function isDenied(): bool;
    public function and(self $other): self; // Both must pass
    public function or(self $other): self;  // Either can pass
}
```

### Policy Implementation

```php
final readonly class {Rule}Policy implements {Name}PolicyInterface
{
    public function evaluate({Subject} $subject, {Resource} $resource): PolicyResult
    {
        if ({condition}) {
            return PolicyResult::allow();
        }
        return PolicyResult::deny('{reason}', ['context' => 'data']);
    }

    public function getRuleName(): string
    {
        return '{rule_name}';
    }
}
```

### Composite Policy

```php
final readonly class {Name}Policy implements {Name}PolicyInterface
{
    public function evaluate({Subject} $subject, {Resource} $resource): PolicyResult
    {
        return $this->rule1Policy->evaluate($subject, $resource)
            ->and($this->rule2Policy->evaluate($subject, $resource))
            ->and($this->rule3Policy->evaluate($subject, $resource));
    }
}
```

---

## Usage Example

```php
// In UseCase
$result = $this->cancellationPolicy->evaluate($user, $order);

if ($result->isDenied()) {
    throw new PolicyViolationException(
        $this->cancellationPolicy->getRuleName(),
        $result->getReason(),
        $result->metadata
    );
}

$order->cancel($reason);
```

---

## Anti-patterns to Avoid

| Anti-pattern | Problem | Solution |
|--------------|---------|----------|
| Side Effects | Policy modifies state | Keep evaluation pure |
| Boolean Returns | No denial reason | Use PolicyResult |
| Fat Policies | Too many rules | Split into composable policies |
| Hardcoded Values | Can't configure | Inject thresholds |
| No Logging Context | Can't debug | Include metadata |

---

## References

For complete PHP templates and examples, see:
- `references/templates.md` — Policy, composite, result templates
- `references/examples.md` — Order cancellation policies and tests

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.