/claude-toolkit:php-best-practicesfrom claude-toolkit
Modernizes, refactors, and enforces standards for PHP 8.2+ codebases. Covers language feature adoption (enums, readonly, match), refactoring patterns, code smell detection, PSR-12 compliance, and Rector-driven upgrades.
Ships in claude-toolkit. 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.
A comprehensive methodology for modernizing, refactoring, and enforcing quality standards in PHP 8.2+ codebases. Covers language feature adoption, refactoring patterns, code smell detection, PSR-12 compliance, and Rector-driven automated upgrades.
| Command | Description |
|---|---|
/php modernize | Upgrade code to use PHP 8.2+ features — enums, readonly, match, named args, null-safe operator, intersection types, DNF types |
/php refactor | Apply refactoring patterns — extract method/class, replace conditional with polymorphism, introduce parameter object, decompose fat controllers |
/php review | Detect code smells and anti-patterns, suggest concrete refactoring steps with before/after examples |
/php standards | Enforce PSR-12, strict types, type coverage, return types, PHPDoc discipline |
/php modernize — Adopt PHP 8.2+ FeaturesAnalyze the user's code and identify opportunities to use modern PHP features. Always show
before/after comparisons. Read references/php82-features.md for the full feature catalog.
| Feature | When to Suggest |
|---|---|
| Enums | Constants used as status/type values, stringly-typed state |
| Readonly properties | Properties set once in constructor, never mutated |
| Readonly classes | All properties are readonly — promote to readonly class |
| Named arguments | Functions with many parameters, boolean flags, optional params |
| Match expressions | Switch statements that return values or assign to a variable |
| Null-safe operator | Chained method calls with null checks at each step |
| Intersection types | Value must satisfy multiple type constraints |
| DNF types | Complex union + intersection type combinations |
| First-class callable syntax | Closure::fromCallable() or [$this, 'method'] patterns |
| Constants in traits | Shared constants across trait users |
| Fibers | Cooperative multitasking, async-like patterns without full async framework |
/php refactor — Apply Refactoring PatternsAnalyze code structure and apply proven refactoring patterns. Read
references/refactoring-catalog.md for the full pattern catalog with examples.
| Smell | Refactoring |
|---|---|
| Method > 20 lines | Extract Method |
| Class > 300 lines | Extract Class |
| 3+ params of same type passed together | Introduce Parameter Object / DTO |
| Switch/if-else on type field | Replace Conditional with Polymorphism |
| Controller > 1 action or > 50 lines | Decompose Fat Controller |
| Deep inheritance tree with override bloat | Replace Inheritance with Composition |
| Repeated inline calculations | Extract Method or Introduce Explaining Variable |
| Method accesses another object's data more than its own | Move Method |
Fat controllers are the most common Laravel anti-pattern. Decompose using:
__invoke()/php review — Code Smell DetectionScan code for smells and anti-patterns. Read references/code-smells.md for the full
catalog with detection heuristics.
For each issue found, present:
SMELL: [Name]
SEVERITY: High / Medium / Low
LOCATION: [File:Line]
DESCRIPTION: [What's wrong and why it matters]
REMEDY: [Specific refactoring to apply]
EXAMPLE: [Before/after snippet if helpful]
| Anti-Pattern | Why It's Bad | Fix |
|---|---|---|
| Stringly-typed code | No IDE support, typo bugs, no exhaustiveness checking | Use enums |
| Array-as-DTO | No type safety, no autocomplete, keys are magic strings | Create a proper DTO class |
@ error suppression | Hides real errors, makes debugging impossible | Handle errors explicitly |
mixed types everywhere | Defeats static analysis, no IDE help | Add specific type declarations |
| God class | Violates SRP, impossible to test in isolation | Extract focused classes |
Service locator / app() everywhere | Hidden dependencies, hard to test | Use constructor injection |
| Business logic in Blade templates | Untestable, hard to maintain | Move to view models or computed properties |
| Raw SQL in controllers | SQL injection risk, not reusable | Use Eloquent scopes or repository pattern |
/php standards — PSR-12 & Type SafetyEnforce coding standards and type coverage across the codebase.
| Standard | Rule |
|---|---|
declare(strict_types=1) | Every PHP file, first statement after <?php |
| PSR-12 formatting | Braces, spacing, line length, blank lines per PSR-12 |
| Return types | Every method must have a return type — no exceptions |
| Parameter types | Every parameter must be typed |
| Property types | Every property must be typed (PHP 7.4+ typed properties) |
| PHPDoc | Only where types cannot express intent — e.g., @template, @param array<string, int>, generics |
No mixed | Replace with specific types or union types |
| Null handling | Prefer null-safe operator or early returns over nested null checks |
PHPDoc is NOT a substitute for type declarations. Use PHPDoc only for:
@param Collection<int, User> $users@param array{name: string, age: int} $data@template T@deprecated Use newMethod() insteadRemove PHPDoc that merely repeats the type declaration:
// BAD — PHPDoc adds nothing
/** @param string $name */
public function setName(string $name): void
// GOOD — no redundant PHPDoc needed
public function setName(string $name): void
Suggest these Rector rule sets for standards enforcement:
TypeDeclarationSet — add missing type declarationsDeadCodeSet — remove unused codeCodingStyleSet — enforce consistent stylePhp82Set — upgrade to PHP 8.2 syntaxRead references/rector-rules.md for the full rule catalog and custom rule creation.
ponytail is installed by default with this toolkit and enforces a minimalism ladder on every
response: skip it → reuse what exists → stdlib → native platform feature → an
already-installed dependency → one line → the minimum that works. Stop at the first rung
that holds.
Apply it before proposing any structure here. The most common failure in this skill's area is a pattern introduced for a problem that does not exist yet:
Reach for a pattern when there is a second case, not in anticipation of one. /ponytail-review
checks a diff for over-engineering; /ponytail-audit sweeps a whole repo. The ladder shortens
the solution — it never shortens the reading you do first.
Rector is assumed to be already installed in the project. This skill helps configure and extend it.
When helping with Rector setup, suggest this starter rector.php:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/app',
__DIR__ . '/config',
__DIR__ . '/database',
__DIR__ . '/routes',
__DIR__ . '/tests',
])
->withPhpSets(php82: true)
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0)
->withPreparedSets(
deadCode: true,
codeQuality: true,
typeDeclarations: true,
earlyReturn: true,
);
--dry-run to see what Rector would changeRead references/rector-rules.md for detailed rule sets and custom rule creation.
| File | Read When |
|---|---|
references/php82-features.md | Modernizing code to PHP 8.2+, explaining new features with examples |
references/refactoring-catalog.md | Applying refactoring patterns, step-by-step transformations |
references/rector-rules.md | Configuring Rector, choosing rule sets, writing custom rules |
references/code-smells.md | Reviewing code for smells, detection heuristics, and remedies |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
43 skills in this plugin
/business-cardSVG business card designer that takes contact details and brand preferences, then produces 12 front design concepts with optional back designs, interactive HTML preview galleries, individual card showcases with front/back flip animation, and print-ready SVG exports with bleed area and crop marks. Supports horizontal and vertical orientations, six layout styles (minimal, corporate, creative, elegant, bold, tech), multiple color schemes, QR code placeholders, social media icons, and logo integration. Use this skill whenever the user asks to design a business card, create a name card, make visiting cards, or says "design business card", "buat kad bisnes", "create name card", "reka kad perniagaan", "design kad nama", "I need a business card for X".
/ci-cd-pipelineCI/CD pipeline builder for Laravel projects — extends Kickoff's existing GitHub Actions CI with continuous deployment pipelines (staging/production), Docker containerisation, secret management, and failure notifications. Generates Dockerfiles, docker-compose.yml, deployment configs for VPS via SSH, container registry push workflows, and leverages Kickoff's /bin scripts (deploy.sh, backup.sh, setup.sh) in automated workflows. Use this skill whenever the user asks to set up deployment pipelines, containerise a Laravel app, configure CD for staging or production, push Docker images to a registry, manage deployment secrets, add failure notifications to CI, or integrate /bin scripts with GitHub Actions. Triggers for requests like "set up CD pipeline", "deploy to staging automatically", "dockerise my Laravel app", "add Docker to my project", "push image to registry", "manage secrets in CI", "notify on failure", "extend CI with deployment", "setup deploy pipeline", "nak deploy guna GitHub Actions", "tambah Docker dalam project", "setup CD untuk staging", "nak auto deploy ke production", "dockerise Laravel app aku", "tambah notification kalau CI fail", "macam mana nak manage secrets dalam GitHub Actions", or "integrate bin scripts dengan CI". Assumes Laravel Kickoff as the baseline — GitHub Actions CI (Pint, PHPStan, Rector, Pest) and /bin scripts (deploy.sh, backup.sh) are already configured. This skill extends that baseline with CD, Docker, and deployment automation.
npx claudepluginhub nasrulhazim/claude --plugin claude-toolkitOther plugins' skills for the same job