From acc
Generates Null Object pattern for PHP 8.4 including interface, null object, real implementation, and unit tests. Eliminates null checks for optional dependencies, missing entities, or feature toggles.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-null-objectThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates Null Object pattern infrastructure for eliminating null checks.
Creates Null Object pattern infrastructure for eliminating null checks.
| Scenario | Example |
|---|---|
| Optional dependencies | Logger, Cache, Notifier |
| Missing entities | Customer, User, Product |
| Feature toggles | Disabled feature returns null object |
| Default implementations | No-op defaults |
Path: src/Domain/{BoundedContext}/
{Name}Interface.php — Interface with isNull() methodPath: src/Domain/{BoundedContext}/
Null{Name}.php — Null implementation returning neutral valuesPath: src/Domain/{BoundedContext}/
{Name}.php — Real implementation with business logicNull{Name}Test.php — Null object behavior tests| Component | Path |
|---|---|
| Interface | src/Domain/{BoundedContext}/ |
| Null Object | src/Domain/{BoundedContext}/ |
| Real Implementation | src/Domain/{BoundedContext}/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/ |
| Component | Pattern | Example |
|---|---|---|
| Interface | {Name}Interface | CustomerInterface |
| Real Implementation | {Name} | Customer |
| Null Object | Null{Name} | NullCustomer |
| Test | {ClassName}Test | NullCustomerTest |
| Type | Neutral Value |
|---|---|
string | '' (empty string) |
int | 0 |
float | 0.0 |
bool | false |
array | [] |
void | No return |
| Object | Empty/default instance |
| Collection | Empty collection |
interface {Name}Interface
{
public function {method1}(): {returnType1};
public function {method2}({params}): {returnType2};
public function isNull(): bool;
}
final readonly class Null{Name} implements {Name}Interface
{
public function {method1}(): {returnType1}
{
return {neutralValue1};
}
public function isNull(): bool
{
return true;
}
}
final readonly class {Name} implements {Name}Interface
{
public function __construct({properties}) {}
public function {method1}(): {returnType1}
{
return {realImplementation};
}
public function isNull(): bool
{
return false;
}
}
final readonly class DoctrineCustomerRepository implements CustomerRepositoryInterface
{
public function findById(CustomerId $id): CustomerInterface
{
$row = $this->connection->fetchAssociative(
'SELECT * FROM customers WHERE id = :id',
['id' => $id->toString()]
);
if ($row === false) {
return new NullCustomer();
}
return $this->hydrate($row);
}
}
final readonly class CreateOrderUseCase
{
public function execute(CreateOrderCommand $command): Order
{
$customer = $this->customers->findById($command->customerId);
// No null check needed - NullCustomer returns 0.0
$discount = $customer->getDiscount();
$order = Order::create(
customerId: $customer->id(),
items: $command->items,
discount: $discount
);
return $order;
}
}
| Anti-pattern | Problem | Solution |
|---|---|---|
| Throwing in Null | Unexpected exceptions | Return neutral values |
No isNull() | Can't detect null object | Add isNull method |
| Different Interface | LSP violation | Same interface as real |
| Side Effects | Unexpected behavior | Pure no-op methods |
| Complex Logic | Not a null object | Keep simple and neutral |
For complete PHP templates and examples, see:
references/templates.md — Interface, NullObject, Real Implementation, NullLogger, NullCache templatesreferences/examples.md — NullCustomer, NullNotifier, Repository integration examples and testsnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accGenerates PHP 8.4 Proxy pattern implementations for lazy loading, caching, access control, and logging. Includes subject interfaces, proxies, and unit tests in domain-driven project paths.
Eliminates null checks by providing default no-op implementations of interfaces for optional dependencies like loggers and caches.
Covers 26 Gang of Four design patterns with PHP 8.3+ implementations, UML diagrams, and practical use cases.