/acc:create-visitorfrom acc
Generates Visitor pattern infrastructure for PHP 8.4: visitor interfaces, concrete visitors, visitable elements, and unit tests. Useful when adding operations to object structures without modifying existing classes.
Ships in acc. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Creates Visitor pattern infrastructure for operations on object structures without modifying classes.
| Scenario | Example |
|---|---|
| Operations on object structure | Calculate price/tax on order items |
| Adding operations without modification | Export visitors (JSON, XML, CSV) |
| Different operations on same elements | Validation, transformation, rendering |
| Double dispatch needed | Type-specific behavior without instanceof |
Path: src/Domain/{BoundedContext}/Visitor/
{Name}VisitorInterface.php — Visitor contract with visit methodsPath: src/Domain/{BoundedContext}/Visitor/ or src/Application/{BoundedContext}/
{Operation1}Visitor.php — First operation implementation{Operation2}Visitor.php — Second operation implementation{Operation3}Visitor.php — Third operation implementationPath: src/Domain/{BoundedContext}/
VisitableInterface.php — Element contract with accept() methodPath: src/Domain/{BoundedContext}/
implements VisitableInterface to element classesaccept() method to each element{Operation}VisitorTest.php — Individual visitor tests{Element}AcceptTest.php — Element accept() tests| Component | Path |
|---|---|
| Visitor Interface | src/Domain/{BoundedContext}/Visitor/ |
| Concrete Visitors (Domain) | src/Domain/{BoundedContext}/Visitor/ |
| Concrete Visitors (Application) | src/Application/{BoundedContext}/Visitor/ |
| Visitable Interface | src/Domain/{BoundedContext}/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/Visitor/ |
| Component | Pattern | Example |
|---|---|---|
| Visitor Interface | {Name}VisitorInterface | OrderItemVisitorInterface |
| Concrete Visitor | {Operation}Visitor | PriceCalculatorVisitor |
| Visitable Interface | VisitableInterface | VisitableInterface |
| Visit Method | visit{ElementType}() | visitProduct() |
| Accept Method | accept() | accept() |
| Test | {ClassName}Test | PriceCalculatorVisitorTest |
interface {Name}VisitorInterface
{
public function visit{Element1}({Element1} $element): {ReturnType};
public function visit{Element2}({Element2} $element): {ReturnType};
public function visit{Element3}({Element3} $element): {ReturnType};
}
final class {Operation}Visitor implements {Name}VisitorInterface
{
public function visit{Element1}({Element1} $element): {ReturnType}
{
// Element1-specific operation
}
public function visit{Element2}({Element2} $element): {ReturnType}
{
// Element2-specific operation
}
}
interface VisitableInterface
{
public function accept({Name}VisitorInterface $visitor): mixed;
}
final readonly class {Element} implements VisitableInterface
{
public function accept({Name}VisitorInterface $visitor): mixed
{
return $visitor->visit{Element}($this);
}
}
// Create elements
$order = new Order(items: [
new Product(price: 100, quantity: 2),
new Service(price: 50, duration: 1),
new Discount(amount: 20),
]);
// Apply different visitors
$priceVisitor = new PriceCalculatorVisitor();
$taxVisitor = new TaxCalculatorVisitor(rate: 0.2);
$exportVisitor = new JsonExportVisitor();
$totalPrice = $order->accept($priceVisitor);
$totalTax = $order->accept($taxVisitor);
$json = $order->accept($exportVisitor);
| Domain | Visitors |
|---|---|
| Order Items | PriceCalculator, TaxCalculator, DiscountApplier |
| AST/Expression Tree | Evaluator, Formatter, Validator |
| Document Structure | Renderer, Counter, Searcher |
| File System | SizeCalculator, Permissions, Backup |
| Shopping Cart | TotalCalculator, ShippingCost, Export |
| Anti-pattern | Problem | Solution |
|---|---|---|
| instanceof in visitor | Defeats purpose | Use proper visit methods |
| Mutable visitor state | Race conditions | Use readonly classes |
| Too many element types | Visitor interface bloat | Split into multiple visitors |
| Breaking element encapsulation | Tight coupling | Expose getters, not internals |
| Returning void | Limited usefulness | Return operation results |
For complete PHP templates and examples, see:
references/templates.md — Visitor Interface, Concrete Visitor, Visitable Element templatesreferences/examples.md — PriceCalculator, TaxCalculator, Export visitors with testsWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub dykyi-roman/awesome-claude-code --plugin acc283 skills in this plugin
/access-control-knowledgeAccess Control knowledge base. Provides ACL, RBAC, ABAC, ReBAC models, multi-tenancy patterns, and PHP implementations (Symfony Voters, Laravel Gates) for security audits and generation./adr-knowledgeAction-Domain-Responder pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for ADR (web-specific MVC alternative) audits./adr-templateGenerates Architecture Decision Records (ADR) for PHP projects. Creates structured decision documentation with context, decision, and consequences.Other plugins' skills for the same job