Command Palette

Search for a command to run...

Назад к скиллам
скилл № 89510

php-best-practices

PHP modernization, refactoring, code review, and standards enforcement assistant for PHP 8.2+ projects. Use this skill whenever the user wants to modernize…

БесплатноБез исполняемых скриптов
nasrulhazimот nasrulhazim★ 26 звёзд на GitHub

Установить php-best-practices в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

PHP Best Practices

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 Reference

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

1. /php modernize — Adopt PHP 8.2+ Features

Analyze 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.

Modernization Checklist

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

Workflow

  1. Read the file or class the user provides
  2. Identify all modernization opportunities, grouped by feature
  3. Present each as a before/after diff with a one-line explanation
  4. If Rector can automate the change, suggest the specific Rector rule
  5. Warn about any breaking changes (e.g., enum vs constant backward compatibility)

2. /php refactor — Apply Refactoring Patterns

Analyze code structure and apply proven refactoring patterns. Read references/refactoring-catalog.md for the full pattern catalog with examples.

Common Refactoring Triggers

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

Workflow

  1. Identify the dominant smell in the code
  2. Name the refactoring pattern to apply
  3. Show the step-by-step transformation (intermediate steps, not just final result)
  4. Verify the refactored code preserves behavior
  5. Suggest tests to add if none exist for the refactored area

Fat Controller Decomposition

Fat controllers are the most common Laravel anti-pattern. Decompose using:

  1. Extract Form Request — validation logic moves to a FormRequest class
  2. Extract Action/Service — business logic moves to an Action or Service class
  3. Extract Resource/Transformer — response shaping moves to an API Resource
  4. Extract Event + Listener — side effects (email, notification, logging) move to events
  5. Single Action Controller — if a controller has one complex action, use __invoke()

3. /php review — Code Smell Detection

Scan code for smells and anti-patterns. Read references/code-smells.md for the full catalog with detection heuristics.

Review Output Format

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-Patterns to Flag

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
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/code-smells.md
  • references/php82-features.md
  • references/rector-rules.md
  • references/refactoring-catalog.md

FAQ

Что делает скилл php-best-practices?

PHP modernization, refactoring, code review, and standards enforcement assistant for PHP 8.2+ projects. Use this skill whenever the user wants to modernize legacy PHP code, refactor messy classes or controllers, review code for smells and anti-patterns, enforce PSR-12 and strict typing standards, or integrate Rector for automated upgrades. Triggers for requests like "modernize my PHP code", "refactor this controller", "review this class for code smells", "enforce strict types", "suggest Rector rules", "upgrade to PHP 8.2 features", "replace this array with a DTO", "decompose this fat controller", or "help me write better PHP". Also triggers for Malay requests like "tolong review code PHP ni", "refactor class ni", "nak upgrade ke PHP 8.2", "code ni messy, tolong clean up", "macam mana nak pakai enum dalam PHP", or "nak buang code smell dalam project ni". Assumes Rector is already installed in the project as a baseline.

Как установить скилл php-best-practices?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл php-best-practices запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить php-best-practices с