/symfony-contribution-skills:symfony-code-contributionfrom symfony-contribution-skills
PHP coding standards, naming conventions, deprecation patterns, and backward-compatibility rules for contributing to Symfony core, bundles, UX, and AI packages. Use when writing or reviewing PHP for a Symfony pull request.
Ships in symfony-contribution-skills. 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.
None: SKILL.md is the whole skill.
Use when writing, modifying, or reviewing PHP code for a contribution to Symfony core or any Symfony-maintained PHP package (bundles, UX PHP side, AI, Mailer, Messenger, Recipes' PHP, etc.).
Do not apply these rules to JavaScript/TypeScript projects such as Webpack Encore or the Stimulus/UX frontend assets — follow that project's own CONTRIBUTING and standards instead. For documentation (.rst) changes, use the symfony-docs-contribution skill.
.php-cs-fixer.dist.php — never hand-format against it: php ./vendor/bin/php-cs-fixer fix -v.trigger_deprecation() call, an @deprecated PHPDoc tag, a CHANGELOG.md entry, and the UPGRADE-*.md entries.namespace.Based on PSR-12 (code style) and PSR-4 (autoloading). The rules below are what PHP CS Fixer enforces and what reviewers check.
Formatting
==, &&, ||, ...) except concatenation (.).!, --, ++) stick to their variable, no space.[ / ] in array access: $a[0], not $a [0].use statement for every class outside the global namespace.Control flow & returns
return, unless the return is alone inside a statement group (e.g. an if).else/elseif/break after an if/case branch that already returns or throws.return null; when returning null; bare return; for void. Do not add a void return type to test methods.Comparisons
=== / !==) unless you explicitly need type juggling.==, !=, ===, !==): if (null === $value).Class layout
setUp() and tearDown() which come first.new Foo().Types
bool, int, float (never boolean/Boolean/integer/double/real).@param/@return type lists, put null last: string|null.PHPDoc
instanceof checks) don't already give.@template-covariant), conditional return types via @psalm-return, class constants, and callable types.@return when the method returns nothing.@author tag with contact info.Exception & error messages
sprintf(), not raw concatenation.get_debug_type($x) for class names in messages (deprecation messages too), not $x::class.The "foo" option ... — never backticks.| Element | Case |
|---|---|
| variables, functions, methods, arguments | camelCase |
| classes, interfaces, traits, enums (always namespaced) | UpperCamelCase |
| enum cases | UpperCamelCase |
| constants | SCREAMING_SNAKE_CASE |
| config params, route names, Twig vars | snake_case |
| PHP files | UpperCamelCase.php |
| templates & web assets | snake_case |
Abstract (except PHPUnit *TestCase); some early classes don't, for BC reasons. Suffix *Interface, *Trait, *Exception. No other suffix such as Class or Enum.As (#[AsCommand], #[AsEventListener]); controller-argument attributes prefixed Map (#[MapEntity], #[MapCurrentUser]).fos_user.something.service_name). Alias the class FQCN to public services.%env(VARIABLE_NAME)%).run, list (not runs, lists).Method naming for collections. Use get set has all replace remove clear isEmpty add register count keys only when the class has one clear "main" relation (a CookieJar -> its cookies; a Container -> its services, not its parameters; a Console Input has none). For other relations, suffix with the thing: getXxx setXxx replaceXxx hasXxx getXxxs (for all) setXxxs (for replace) removeXxx clearXxx isEmptyXxx addXxx registerXxx countXxx; no keys equivalent. setXxx() may add or replace; replaceXxx() must not add and throws on an unknown key.
@deprecated since Symfony X.Y, use Bar instead. — state the version and, whenever possible, the replacement (FQCN if in another namespace).symfony/deprecation-contracts):
trigger_deprecation('symfony/package', '7.3', 'The "%s" class is deprecated, use "%s" instead.', Foo::class, Bar::class);
For a deprecated class, place the call after the use block, before the class definition.CHANGELOG.md (component root), UPGRADE-X.Y.md (this minor, under the component heading), UPGRADE-X.0.md (next major, the consequence: * Remove the `Foo` class, use `Bar` instead).CHANGELOG.md entry (* Remove the `Foo` class, use `Bar` instead) in the same PR.CHANGELOG.md entries (new features and deprecations, at the root of the modified component, bridge or bundle):
CHANGELOG; each entry is a list item under a minor-version section (7.3); no third-level sections.* Deprecate the `Foo` class, use `Bar` instead.CHANGELOG-* files at the symfony/symfony root.Minor releases keep BC; only majors may break it. When unsure, keep the old API and deprecate. Excluded from the promise: @internal, @experimental and *\Tests\ code, plus Symfony's security/validation translations. A BC break is tolerated only when required to fix a security issue.
Never, on public/protected API: remove, rename or re-namespace a class/interface/trait/method/property/constant; make a class final or abstract; remove an implemented interface; remove a constructor or destructor; add an argument without a default (constructors included); add an optional argument to a method (use the recipe below); remove an argument other than the last optional one(s); change or remove a default value; add a default to a method argument; add or change an argument type; add, remove or change a return type (removing void is allowed); reduce visibility; make a protected member public; flip static/non-static.
Allowed: add public/protected methods, properties and constants, an interface, a destructor; add a constructor argument with a default, at the end (anywhere after the required ones under @optional-arguments-by-name/@arguments-by-name); add a default to a constructor argument (not under @optional-arguments-by-name); remove a constructor argument's type; rename an argument whose name is not covered (see below); change the parent class if the original stays an ancestor; move a member to a parent class; anything on a class's private members.
Avoid, and document in the UPGRADE file if done: adding a constructor without mandatory arguments; changing a constant's value. Never change a constant used in YAML/XML config (e.g. event names) or likely to be serialized.
final loosens the rules. A class/method that is native final or plain @final (not @final since Symfony x.y) also allows: removing, renaming, reducing or publicizing protected members; adding optional arguments and defaults (not under @optional-arguments-by-name); adding, removing or changing argument and return types (arguments -> parent type only, returns -> child type only); turning non-static into static.
Interfaces are strictest: you may add a parent interface that introduces no new method, move a method to a parent interface, add constants, and change a constant's value (same caveats). Nothing else.
Traits: never give one a constructor or destructor. Private members are covered too, since using classes call them: don't remove, rename or change their signature; you may make them public/protected or move them to a used trait.
Parameter names are covered only for Attribute-class constructors and methods tagged:
@optional-arguments-by-name: optional params' names covered (not order), required params' order covered (not names).@arguments-by-name: all names covered, not order.@stable-parameter-names: names and order covered.Covered names never change. A tag on a class/interface/trait/enum applies to all its public and protected methods (private ones too in traits). When implementing or overriding a tagged method (constructors excepted), keep the same parameter names.
Adding a new argument to a public method (last position only):
public function say(string $text, /* bool $stripWhitespace = true */): void (drop = true if it will be required).@param bool $stripWhitespace.$stripWhitespace = 2 <= \func_num_args() ? func_get_arg(1) : false; — the fallback keeps the current behavior.trigger_deprecation('symfony/COMPONENT', 'X.Y', 'Not passing the "bool $stripWhitespace" argument explicitly is deprecated, its default value will change to X in Z.0.');
if (\func_num_args() < 2) {
trigger_deprecation('symfony/COMPONENT', 'X.Y', 'The "%s()" method will have a new "bool $stripWhitespace" argument in version Z.0, not defining it is deprecated.', __METHOD__);
$stripWhitespace = false;
} else {
$stripWhitespace = func_get_arg(1);
}
Z.0): uncomment the argument, drop the PHPDoc if it adds no description, remove the func_get_arg() code and the warning.final keyword
final is a BC break. So is adding a plain @final in a minor.@final since Symfony x.y. In the next major, switch to native final or drop the since Symfony x.y part.DebugClassLoader copies the text after @final verbatim into the deprecation message (The "..." class is considered final since Symfony 8.1): keep it short and accurate.Experimental features: tag classes/methods @experimental. One minor version at most (the core team may extend by one); never introduced in an LTS. The CHANGELOG must explain every BC-incompatible change and how to upgrade.
Patch releases of a maintained minor ship monthly and accept only tightly-scoped changes. When targeting a maintained branch, fix the bug and nothing else.
Accepted in a patch: bug fixes that keep valid tests green, add a covering test, and don't change buggy behavior widely used as a "feature"; support for newer PHP or popular OS versions (Linux, macOS, Windows) — never new PHP features; translation updates and additions (always on the oldest maintained branch); external-data refreshes (e.g. ICU); raising a dependency's minimum version (not to a new major, never the PHP minimum); tests that raise coverage.
Generally rejected (case by case, mostly for security fixes): performance work (unless local to one class, algorithmic, and backed by real-world numbers); coding-standard/refactor churn (only for consistency, non-invasive, no complex merge-up); new classes, public/protected methods or global functions; new config options (never); new deprecations (none once a version is stable); adding/updating annotations (fixing wrong ones may pass).
Never in a patch — do it on the next minor/major: new features; security hardening; BC breaks (unless no other way to fix a security issue); support for new external platforms (e.g. Google App Engine); changing exception messages (automated tools rely on them); new Composer deps or support for new majors of existing ones; web-design changes to built-in pages (exceptions, toolbar, profiler).
When docs or PHPDoc disagree with the code, the code is authoritative.
symfony/symfony or the target package) to your account; clone; git remote add upstream <canonical>.git checkout -b my_change upstream/<branch>.trigger_deprecation + @deprecated + CHANGELOG.md + UPGRADE-*.md.php ./vendor/bin/php-cs-fixer fix -v and run the component tests (./phpunit src/Symfony/Component/Xxx).Canonical sources live in symfony/symfony-docs and stay in sync — read the .rst when a case is unclear:
contributing/code/standards.rstcontributing/code/conventions.rstcontributing/code/bc.rstcontributing/code/maintenance.rst| Bad | Good |
|---|---|
if ($value == null) | if (null === $value) |
throw new \RuntimeException('Invalid '.$type.' given') | throw new \RuntimeException(sprintf('Invalid "%s" given.', $type)) |
throw new \LogicException('The `debug` option ...') | throw new \LogicException('The "debug" option ...') |
$class = $object::class; (in a message) | $class = get_debug_type($object); |
| removing a public method in 7.x | @deprecated it in 7.x, remove in 8.0 |
adding bool $strict as a real param in a minor | comment it out, read via func_get_arg(), deprecate if needed |
adding @final to a class in a minor | @final since Symfony 8.2, native final in 9.0 |
renaming a parameter of an @arguments-by-name method | keep the name; covered names never change |
public function all() { ... } renamed to getAll() | keep all(); it is the standard main-relation name |
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub kocal/symfony-contribution-skills --plugin symfony-contribution-skills2 skills in this plugin