resources/boost/skills/php/SKILL.md
General PHP coding standards covering strict typing, formatting, control flow, and error handling. Applies to all PHP files in the application.
npx skillsauth add codebar-ag/coding-guidelines phpInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
app/, tests/, and supporting project PHP files).phpstan, controllers, requests, etc.).?Type) where neededelse, elseif, or nested if blocks — invert the condition and return earlyreadonly properties where possible; use mutable properties only when state must evolve across method callselse rule.// ✓ Early returns — guard clauses
public function process(Order $order): void
{
if (! $order->isPaid()) {
throw new UnpaidOrderException();
}
if (! $order->hasItems()) {
throw new EmptyOrderException();
}
// Happy-path logic here
}
// ✗ Nested if/else — never do this
public function process(Order $order): void
{
if ($order->isPaid()) {
if ($order->hasItems()) {
// deep logic
} else {
throw new EmptyOrderException();
}
} else {
throw new UnpaidOrderException();
}
}
// ✓ Fully typed class
class CreateInvoice
{
public function __construct(
private readonly GenerateInvoicePdf $generatePdf,
) {}
public function execute(Order $order): Invoice
{
// implementation
}
}
// ✗ Anti-pattern: swallowed exception
try {
$this->externalService->call($data);
} catch (Throwable $e) {
// no logging, no rethrow, no fallback
}
// ✓ Structured logging when catching
try {
$this->externalService->call($data);
} catch (ServiceException $e) {
Log::error('External service failed.', [
'message' => $e->getMessage(),
'data' => $data,
]);
throw $e;
}
// ✓ Retry transient failures, then catch once for context and rethrow
try {
return retry(3, fn () => $this->gateway->charge($payload), 200);
} catch (GatewayTimeoutException $e) {
Log::warning('Charge failed after retries.', ['order_id' => $orderId]);
throw $e;
}
// ✓ Foreign-language DTO terms are acceptable when mirroring external API fields
readonly class AdresseData
{
public function __construct(
public string $ID,
public ?string $Strasse,
public ?string $PLZ,
) {}
}
else or elseif — invert and return early insteadenv() directly in application code (only in config files)mixed access/calls without narrowing@phpstan-ignore* as last resort; each usage needs an inline reason.pint.json (if present) defines local Pint behaviorphpstan.neon defines local static-analysis scope and strictnessPHPStan/SKILL.md — static analysis complianceelse/elseiftesting
Translation and localization conventions for Laravel. Use when adding user-facing strings, creating translation files, or working with lang/ directory.
tools
Reusable behaviour shared across multiple unrelated classes. Traits provide shared Eloquent scopes, accessors, lifecycle hooks, and small stateless helper methods.
development
Tailwind CSS v4 styling conventions. Use when working with CSS, Tailwind utilities, or customizing the theme in Laravel projects.
development
Orchestration classes that coordinate multiple Actions, external APIs, or domain operations into a cohesive workflow. Services own transaction boundaries and third-party API integrations.