/spwf:php-code-simplifierfrom spwf
Simplify and refactor PHP code for clarity, type safety, and maintainability while preserving exact behaviour. Use after implementing a feature or fixing a bug in PHP codebases (Laravel, Symfony, WordPress, or plain PHP). Focuses on recently modified files unless a path is provided. Never changes what code does — only how it does it. Complement to the core simplify skill, which is language-agnostic; this skill knows PHP idioms, framework conventions, and version-specific capabilities. Called as a step by the php-code-simplifier agent, which is why Claude may invoke it. Do not start it unprompted: run it standalone only when the user asks.
Ships in spwf. 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; scripts run unread.
Refactor PHP code for clarity and maintainability while preserving exact behaviour. Read the code, apply safe improvements, flag judgment calls without touching them.
references/php-version-capabilities.md if unsure.if/match beats a clever one-liner. A named method beats an inline lambda.references/*.md before touching framework code.# PHP version
cat composer.json 2>/dev/null | grep '"php"'
php --version 2>/dev/null | head -1
# Framework
grep -l "laravel/framework\|illuminate/" composer.json composer.lock 2>/dev/null && echo "Laravel"
grep -l "symfony/framework-bundle\|symfony/http-kernel" composer.json composer.lock 2>/dev/null && echo "Symfony"
grep -rn "add_action\|add_filter\|wp_enqueue" --include="*.php" . -l 2>/dev/null | head -1 && echo "WordPress"
Record the PHP version. Load the corresponding reference file:
references/laravel-patterns.mdreferences/symfony-patterns.mdreferences/wordpress-patterns.mdIf a path argument was given, use it. Otherwise:
git diff --name-only main...HEAD -- '*.php'
Exclude:
tests/, test/, spec/, *Test.php, *Spec.php, *_test.phpvendor/, node_modules/If no files remain: report "No non-test PHP files changed on this branch."
Read each file. Work through the patterns below. For each: apply if confidence is high and behaviour is provably preserved; flag otherwise.
// Flag — nested conditions
if ($user) {
if ($user->isActive()) {
if ($user->canPurchase()) {
$this->process($user);
}
}
}
// Prefer — guard clauses
if (!$user || !$user->isActive() || !$user->canPurchase()) {
return;
}
$this->process($user);
Apply when: all branches are simple guards with early returns. Flag when there is meaningful logic in the nested branches that changes behaviour if flattened.
// Before
$name = null;
if ($user && $user->profile) {
$name = $user->profile->name;
}
// After
$name = $user?->profile?->name;
Apply only when null propagation is the intended behaviour. If the original code has distinct handling for each null case, flag instead.
match over switch for value mapping (apply if PHP ≥ 8.0)// Before
switch ($role) {
case 'admin':
return true;
case 'editor':
return true;
default:
return false;
}
// After
return match ($role) {
'admin', 'editor' => true,
default => false,
};
Apply when: every case is a simple return or assignment with no side effects. match is strict (===) — flag if the original switch relied on loose comparison.
Remove: var_dump(, dd(, dump(, ray(, print_r(, var_export( — any that are not behind a conditional or test context.
Flag (do not remove): debug calls inside if (config('app.debug')) or similar — these may be intentional.
// Flag — untyped
function calculate($items, $tax) { ... }
// Suggest
function calculateTotal(array $items, Money $tax): Money { ... }
Always flag, never apply — adding types changes the signature and can break call sites or fail at runtime if the actual types differ.
// Flag
if ($status === 'pending') { ... }
if ($status === 'p') { ... }
// Suggest
if ($status === OrderStatus::Pending) { ... }
Flag only — creating an enum is a larger change that affects persistence, serialisation, and all call sites.
match / enums over boolean parameters (flag only)// Flag — boolean parameter hides intent
sendEmail($user, true, false);
// Suggest — named method or options object
sendWelcomeEmail($user);
sendEmailWithOptions($user, EmailOptions::withoutAttachment());
// Flag — verbose DTO
class CreateUserDTO {
public string $name;
public string $email;
public function __construct(string $name, string $email) {
$this->name = $name;
$this->email = $email;
}
}
// Suggest
final readonly class CreateUserDTO {
public function __construct(
public string $name,
public string $email,
) {}
}
Flag only — readonly changes mutability semantics; verify no code assigns these properties after construction.
// Before
$value = isset($data['key']) ? $data['key'] : 'default';
// After
$value = $data['key'] ?? 'default';
Apply when: the original uses isset purely to provide a default. Do not apply if null is a meaningful value that should be distinguished from "missing".
Remove blocks of commented-out code. Leave in place:
/** */)## PHP Simplify Report
**PHP version**: {version}
**Framework**: {Laravel | Symfony | WordPress | Plain PHP}
**Files reviewed**: {N}
### Applied
- `{file}:{line range}` — {what was changed and why}
### Flagged (judgment needed)
- `{file}:{line}` — {pattern} — {suggested fix} [confidence: medium|low]
### Clean
- `{file}` — no changes needed
### Skipped
- `{file}` — {reason: generated migration | test file | vendor}
match is strict, switch is loose. Replacing switch with match changes == to ===. A switch ('1') with case 1: matches; a match ('1') with 1 => does not. Always check whether the original relied on type coercion.$a?->b()?->c() returns null if $a is null — it does not call b() or c(). If the original code had side effects in those calls, nullsafe changes behaviour.readonly, verify nothing outside the constructor writes to the property.esc_html, esc_attr, esc_url, esc_js each encode differently. Do not swap them. Load references/wordpress-patterns.md before touching any WordPress output code.Load on demand:
references/php-version-capabilities.md — feature availability by PHP version (8.0–8.3+)references/laravel-patterns.md — Eloquent, service containers, middleware, form requestsreferences/wordpress-patterns.md — escaping, nonces, capabilities, $wpdb, hooksreferences/symfony-patterns.md — DI, voters, events, commandsreferences/php-smell-catalog.md — full smell list with detection patternsreferences/laravel-patterns.md (opens in a new tab)references/php-smell-catalog.md (opens in a new tab)references/php-version-capabilities.md (opens in a new tab)references/symfony-patterns.md (opens in a new tab)references/wordpress-patterns.md (opens in a new tab)scripts/analyse-php.sh (opens in a new tab)scripts/php-quality-baseline.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
38 skills in this plugin
/address-reviewPhase 6.5 — Address Review. Turn review feedback into action. Sources feedback from either a local report file (e.g. {branch}-review.md from /spwf:pr-review or {branch}-self-review.md from /spwf:simplify) or fetched human comments on an open PR/MR. For each item runs READ → VERIFY → EVALUATE → implement-or-push-back, in priority order (blocking → important → nit). Forbids performative agreement ("you're absolutely right"). Use after pr-review, or whenever a reviewer leaves comments./agent-optimiseCross-cutting — Audit both the project .claude/ and personal ~/.claude/ for quality issues. Covers CLAUDE.md scope and length, agent descriptions, skill frontmatter, and settings.json conflicts. Always audits both scopes. Produces a prioritised P1/P2/P3 fix list./npx claudepluginhub simon-potter/spwf --plugin spwf