If you need any help, don't hesitate to ask the community using GitHub Discussions.
A fixer is a class that tries to fix a single code style issue (a Fixer
class must implement FixerInterface
).
A ruleset is a collection of rules (fixers) that may be referenced in the config file similarly to a single fixer. When you work on existing fixer please keep in mind it can be a part of a ruleset(s) and changes may affect many users. When working on new fixer please consider if it should be added to some ruleset(s).
A config knows about the code style rules and the files and directories that must be scanned by the tool when run in the context of your project. It is useful for projects that follow a well-known directory structures, but the tool is not limited to any specific structure, and you can configure it in a very flexible way.
[!IMPORTANT] Before contributing with really significant changes that require a lot of effort or are crucial from this tool's architecture perspective, please open RFC on GitHub Discussion. The development effort should start only after the proposal is discussed and the approach aligned.
gh
CLI tool.master
branch (if you already had project locally, then make sure to update this branch before going to next steps). It's good when branch's name reflects intent of the changes, but this is not strict requirement since pull request provides description of the change. However, with good branch naming it's easier to work on multiple changes simultaneously.composer update
(since project does not contain composer.lock
it's better to ensure latest versions of packages by running update
command instead of install
).yield
with proper case description as a key (e.g. yield 'Some specific scenario' => ['some', 'example', 'data'];
). Codebase may still contain test cases in different format, and it's totally acceptable to use yield
approach next to existing return
usages.composer docs
. This requires the highest version of PHP supported by PHP CS Fixer. If it is not installed on your system, you can run it in a Docker container instead: docker compose run php-8.2 php dev-tools/doc.php
.composer qa
.composer cs:fix
.You can do some things to increase the chance that your pull request is accepted without communication ping-pong between you and the reviewers:
foo
, more work
, more work
, more work
) and don't push complex PR as a single commit.PhpCsFixer\Console\Application::VERSION
, it's done during release.[!IMPORTANT] Your pull request will have much higher chance of getting merged if you allow maintainers to push changes to your branch. You can do it by ticking "Allow edits and access to secrets by maintainers" checkbox, but please keep in mind this option is available only if your PR is created from a user's fork. If your fork is a part of organisation, then you can add Fixer maintainers as members of that repository. This way maintainers will be able to provide required changes or rebase your branch (only up-to-date PRs can be merged).
This project provides a Docker setup that allows working on it using any of the PHP versions supported by the tool.
To use it, you first need to install Docker (Docker Compose is a built-in plugin of the main tool).
Next, copy compose.override.dist.yaml
to compose.override.yaml
and edit it to your needs. The relevant parameters that might require some tweaking have comments to help you.
You can then build the images:
docker compose build --parallel
Now you can run commands needed to work on the project. For example, say you want to run PHPUnit tests on PHP 8.2:
docker compose run php-8.2 vendor/bin/phpunit
Sometimes it can be more convenient to have a shell inside the container:
docker compose run php-7.4 sh
/fixer vendor/bin/phpunit
The images come with an xdebug
script that allows running any PHP command with Xdebug enabled to help debug problems.
docker compose run php-8.2 xdebug vendor/bin/phpunit
If you're using PhpStorm, you need to create a server with a name that matches the PHP_IDE_CONFIG
environment variable defined in the Docker Compose configuration files, which is php-cs-fixer
by default.
All images use port 9003 for debug connections.
There is a cookbook with basic instructions on how to build a new fixer. Consider reading it before opening a PR.