No slash command · from php-foundation
Encodes modern PHP 8.1+ idioms: readonly properties, enums, match expressions, constructor property promotion, typed properties, named arguments, nullsafe operator, first-class callable syntax, strict_types, and PSR-12 style. Apply to any PHP project for strongly-typed, immutable-by-default code.
Ships in php-foundation. 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.
None: SKILL.md is the whole skill.
This skill encodes idioms that reduce bugs and improve readability in any PHP codebase. Apply alongside the active framework plugin's conventions skill (e.g., laravel-plugin:laravel-conventions, symfony-plugin:symfony-conventions).
Read composer.json first to learn the target PHP version:
"require": { "php": "^8.1" } (or higher) → all idioms below apply."config": { "platform": { "php": "8.x" } } pins the resolver version.Match the project's minimum version — do not use PHP 8.2+ features (e.g. readonly classes, DNF types) on an 8.1 project.
Every .php file with logic starts with:
<?php
declare(strict_types=1);
namespace App\Domain;
Strict typing turns silent coercions into TypeErrors at the boundary, catching bugs early. The declaration must be the first statement.
Collapse the declare/assign boilerplate into the signature.
// Prefer
final class Money
{
public function __construct(
public readonly int $amount,
public readonly Currency $currency,
) {
}
}
// Avoid — manual field + assignment
final class Money
{
private int $amount;
private Currency $currency;
public function __construct(int $amount, Currency $currency)
{
$this->amount = $amount;
$this->currency = $currency;
}
}
final class OrderLine
{
public function __construct(
public readonly string $sku,
public readonly int $quantity,
) {
}
public function withQuantity(int $quantity): self
{
return new self($this->sku, $quantity); // return a new instance, never mutate
}
}
readonly properties can be assigned once (from within the declaring scope) and never again. Use them for value objects and DTOs. On PHP 8.2+ a whole class may be marked readonly.
Use backed enums for closed sets of values; attach behaviour with methods.
enum Status: string
{
case Draft = 'draft';
case Active = 'active';
case Archived = 'archived';
public function isPublished(): bool
{
return $this === self::Active;
}
public function label(): string
{
return match ($this) {
self::Draft => 'Draft',
self::Active => 'Active',
self::Archived => 'Archived',
};
}
}
$status = Status::from('active'); // throws ValueError on unknown
$maybe = Status::tryFrom($input); // null on unknown
Never model a closed set with bare string constants or class const lists when a backed enum fits.
$discount = match (true) {
$total >= 1000 => 0.15,
$total >= 500 => 0.10,
$total >= 100 => 0.05,
default => 0.0,
};
match uses strict comparison (===), has no fallthrough, and throws UnhandledMatchError if nothing matches and no default is present — far safer than switch.
final class UserService
{
public function findById(int $id): ?User // explicit nullable return
{
return $this->repository->find($id);
}
/** @return list<User> */
public function active(): array // PHPDoc narrows array element type
{
return $this->repository->whereActive();
}
}
?T for nullable, union types (int|string) where genuinely needed.list<T>, array<K, V>) so static analysers (PHPStan/Psalm) can check element types.$country = $order?->customer?->address?->country; // short-circuits to null
// Validate at boundaries instead of propagating null
public function charge(Customer $customer): void
{
$card = $customer->defaultCard()
?? throw new NoPaymentMethodException($customer->id);
// ...
}
null to signal errors from public methods — throw a domain exception or return an empty collection.$response = $client->request(
method: 'POST',
uri: '/orders',
options: ['json' => $payload],
);
Use named arguments to clarify boolean/optional parameters at the call site. Do not reorder — pass them in declaration order for readability.
$names = array_map(strtoupper(...), $words);
$ids = array_map($user->id(...), $users);
Prefer $callable(...) over string callable names or array [$obj, 'method'] forms.
<?php (no closing ?>).final by default; open for extension only when designed for it.@PSR12 / @Symfony ruleset). Do not hand-tune whitespace the formatter owns.private/protected by default, public only when needed.interface; depend on abstractions, not concretions.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub aratkruglik/claude-sdlc --plugin php-foundation3 skills in this plugin
/composer-toolingComposer conventions for any PHP project: dependency management, version constraints, PSR-4 autoloading, scripts, platform requirements, and the composer.json vs composer.lock contract. Stack-agnostic — referenced by every PHP plugin in the marketplace.
Use this skill to:
- Read composer.json to detect the PHP version, framework, and key packages before writing code.
- Add dependencies with correct version constraints and the right require vs require-dev placement.
- Configure PSR-4 autoloading and regenerate the autoloader after adding namespaces.
- Use composer scripts and platform config consistently.
Do NOT use this skill for:
- PHP language idioms — see php-foundation:php-conventions.
- Testing setup and runners — see php-foundation:php-testing.
- Framework-specific package guidance (Laravel/Symfony bundles) — those live in framework plugin skills.
/php-testingPHPUnit and Pest patterns for any PHP project: test structure, naming, data providers, test doubles (mocks/stubs/fakes), fixtures, and coverage targets. Stack-agnostic — referenced by every PHP plugin in the marketplace.
Use this skill to:
- Structure unit and integration tests with PHPUnit or Pest consistently.
- Drive cases with data providers / datasets instead of copy-pasted test bodies.
- Use test doubles with discipline — mock collaborators, not the system under test.
- Set up and tear down fixtures cleanly and aim for a meaningful coverage target.
Do NOT use this skill for:
- PHP language idioms — see php-foundation:php-conventions.
- Composer / autoloading — see php-foundation:composer-tooling.
- Framework-specific test helpers (Laravel RefreshDatabase/actingAs, Symfony WebTestCase/KernelTestCase) — those are injected by the framework plugin's QA phase.
Other plugins' skills for the same job