Agent skill
phpstan
Static analysis tool configured at Level 9. All code must pass PHPStan Level 9 with strict typing, no untyped signatures, and minimal suppression of errors.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/phpstan
SKILL.md
Name: PHPStan Description: Static analysis tool configured at Level 9. All code must pass PHPStan Level 9 with strict typing, no untyped signatures, and minimal suppression of errors. Compatible Agents: general-purpose, testing, backend Tags: app//*.php, tests//*.php, laravel, php, static-analysis, phpstan, types
Rules
- All code must pass PHPStan Level 9
- Type hints on all parameters, return types, and properties — no untyped signatures
- No
@phpstan-ignoreunless documented with a justification comment - Use
phpstan-assert,phpstan-param, andphpstan-returnPHPDoc tags when generics or complex types are needed - Replace
mixedwith specific union types where possible - Use
array<string, mixed>instead of barearrayin PHPDoc - Add
@throwsannotations for methods that throw exceptions - Use
assert()or type narrowing instead of suppressing errors
Examples
// ✓ Specific types instead of mixed
public function process(Order $order): Invoice { ... }
// ✓ PHPDoc with typed arrays
/**
* @return array<string, array<int, string|object>>
*/
public function rules(): array { ... }
// ✓ Union types instead of mixed
public function format(string|int|null $value): string { ... }
// ✓ Generics for collections
/**
* @return Collection<int, Invoice>
*/
public function getInvoices(): Collection { ... }
// ✓ @throws annotation
/**
* @throws InvoiceAlreadyPaidException
*/
public function markAsPaid(Invoice $invoice): void
{
if ($invoice->isPaid()) {
throw InvoiceAlreadyPaidException::for($invoice);
}
// ...
}
// ✓ Type narrowing with assert() instead of suppression
public function handle(mixed $model): void
{
assert($model instanceof Invoice);
$model->markAsPaid(); // PHPStan now knows it's an Invoice
}
// ✓ Justified suppression with comment
/** @phpstan-ignore-next-line Property accessed via magic method — documented in IDE helper */
$user->custom_attribute;
Anti-Patterns
- Using bare
mixedtypes when a more specific type is possible - Using bare
arraywithout a PHPDoc generic shape:array<string, mixed> - Using
@phpstan-ignorewithout a comment explaining why it is necessary - Omitting
@throwsannotations on methods that throw - Leaving parameters, return types, or properties untyped
- Using
(int),(string)casts as substitutes for proper type narrowing
References
- PHPStan Documentation
- PHPStan Rule Levels
- Related:
PHP/SKILL.md— general PHP conventions including strict typing
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?