Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

php-best-practices

БесплатноБез исполняемых скриптовНе проверен

PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best…

AsyrafHussinот AsyrafHussin★ 112 звёзд на GitHub4 установки в других каталогах

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

PHP Best Practices

Modern PHP 8.x patterns, PSR standards, type system best practices, and SOLID principles. Contains 57 rules for writing clean, maintainable PHP code.

Step 1: Detect PHP Version

Always check the project's PHP version before giving any advice. Features vary significantly across 8.0 - 8.6. Never suggest syntax that doesn't exist in the project's version.

Check composer.json for the required PHP version:

{ "require": { "php": "^8.1" } }   // -> 8.1 rules and below
{ "require": { "php": "^8.3" } }   // -> 8.3 rules and below
{ "require": { "php": ">=8.4" } }  // -> 8.4 rules and below
{ "require": { "php": "^8.6" } }   // -> all rules

Also check the runtime version:

php -v   # e.g. PHP 8.3.12

Feature Availability by Version

Feature Version Rule Prefix
Union types, match, nullsafe, named args, constructor promotion, attributes 8.0+ type-, modern-
Enums, readonly properties, intersection types, first-class callables, never, fibers 8.1+ modern-
Readonly classes, DNF types, true/false/null standalone types 8.2+ modern-
Typed class constants, #[\Override], json_validate() 8.3+ modern-
Property hooks, asymmetric visibility, #[\Deprecated], new without parens 8.4+ modern-
Pipe operator ` >` 8.5+
Partial function application (f(?, 1)), readonly property defaults, clamp(), Time\Duration, SortDirection, #[\Override] on constants, stream error exceptions, secure session defaults 8.6+ modern-, error-, sec-

Only suggest features available in the detected version. If the user asks about upgrading or newer features, mention what becomes available at each version.

When to Apply

Reference these guidelines when:

  • Writing or reviewing PHP code
  • Implementing classes and interfaces
  • Using PHP 8.x modern features
  • Ensuring type safety
  • Following PSR standards
  • Applying design patterns

Rule Categories by Priority

Priority Category Impact Prefix Rules
1 Type System CRITICAL type- 9
2 Modern PHP Features CRITICAL modern- 20
3 PSR Standards HIGH psr- 6
4 SOLID Principles HIGH solid- 5
5 Error Handling HIGH error- 6
6 Performance MEDIUM perf- 5
7 Security CRITICAL sec- 6

Quick Reference

1. Type System (CRITICAL) — 9 rules

  • type-strict-mode - Declare strict types in every file
  • type-return-types - Always declare return types
  • type-parameter-types - Type all parameters
  • type-property-types - Type class properties
  • type-union-types - Use union types effectively
  • type-intersection-types - Use intersection types
  • type-nullable-types - Handle nullable types properly
  • type-void-never - Use void/never for appropriate return types
  • type-mixed-avoid - Avoid mixed type when possible

2. Modern PHP Features (CRITICAL) — 20 rules

8.0+:

  • modern-constructor-promotion - Constructor property promotion
  • modern-match-expression - Match over switch
  • modern-named-arguments - Named arguments for clarity
  • modern-nullsafe-operator - Nullsafe operator (?->)
  • modern-attributes - Attributes for metadata

8.1+:

  • modern-enums - Enums instead of constants
  • modern-enums-methods - Enums with methods and interfaces
  • modern-readonly-properties - Readonly for immutable data
  • modern-first-class-callables - First-class callable syntax
  • modern-arrow-functions - Arrow functions (7.4+, pairs well with 8.1 features)

8.2+:

  • modern-readonly-classes - Readonly classes

8.3+:

  • modern-typed-constants - Typed class constants (const string NAME = 'foo')
  • modern-override-attribute - #[\Override] to catch parent method typos (constants and enum cases 8.6+)

8.4+:

  • modern-property-hooks - Property hooks replacing getters/setters
  • modern-asymmetric-visibility - public private(set) for controlled access

8.5+:

  • modern-pipe-operator - Pipe operator (|>) for functional chaining

8.6+:

  • modern-partial-application - str_replace(' ', '-', ?) instead of wrapper closures
  • modern-readonly-defaults - Default values on readonly properties
  • modern-clamp - clamp($v, min, max) instead of nested min/max
  • modern-time-duration - Time\Duration instead of bare seconds/milliseconds

3. PSR Standards (HIGH) — 6 rules

  • psr-4-autoloading - Follow PSR-4 autoloading
  • psr-12-coding-style - Follow PSR-12 coding style
  • psr-naming-classes - Class naming conventions
  • psr-naming-methods - Method naming conventions
  • psr-file-structure - One class per file
  • psr-namespace-usage - Proper namespace usage

4. SOLID Principles (HIGH) — 5 rules

  • solid-srp - Single Responsibility: one reason to change
  • solid-ocp - Open/Closed: extend, don't modify
  • solid-lsp - Lisko
Полный SKILL.md на GitHub

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

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

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

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

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

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

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

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

AGENTS.mdREADME.mdmetadata.jsonrules/_sections.mdrules/_template.mdrules/error-custom-exceptions.mdrules/error-exception-hierarchy.mdrules/error-finally-cleanup.mdrules/error-never-suppress.mdrules/error-stream-errors.mdrules/error-try-catch-specific.mdrules/modern-arrow-functions.mdrules/modern-asymmetric-visibility.mdrules/modern-attributes.mdrules/modern-clamp.mdrules/modern-constructor-promotion.mdrules/modern-enums-methods.mdrules/modern-enums.mdrules/modern-first-class-callables.mdrules/modern-match-expression.mdrules/modern-named-arguments.mdrules/modern-nullsafe-operator.mdrules/modern-override-attribute.mdrules/modern-partial-application.mdrules/modern-pipe-operator.mdrules/modern-property-hooks.mdrules/modern-readonly-classes.mdrules/modern-readonly-defaults.mdrules/modern-readonly-properties.mdrules/modern-time-duration.mdrules/modern-typed-constants.mdrules/perf-array-functions.mdrules/perf-avoid-globals.mdrules/perf-generators.mdrules/perf-lazy-loading.mdrules/perf-string-functions.mdrules/psr-12-coding-style.mdrules/psr-4-autoloading.mdrules/psr-file-structure.mdrules/psr-namespace-usage.md

FAQ

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

PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best practices. Triggers on "review PHP", "check PHP code", "audit PHP", or "PHP best practices".

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

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

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

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

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

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