paysera / lib-php-cs-fixer-config
PHP CS Fixer config for Paysera conventions
Installs: 32 348
Dependents: 6
Suggesters: 0
Security: 0
Stars: 9
Watchers: 9
Forks: 18
Open Issues: 7
Requires
- php: >=7.4 <8.0 || >=8.1
- doctrine/inflector: ^1.0 || ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.64.0
- phpunit/phpunit: ^9.3.0
- sanmai/phpunit-legacy-adapter: ^6.4 || ^8.2
Suggests
- paysera/lib-arcanist-php-cs-extension: Integrates PHP CS Fixer into arcanist workflow
- dev-master
- 3.0.2
- 3.0.1
- 3.0.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.0
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- dev-dependabot/composer/friendsofphp/php-cs-fixer-2.18.2
- dev-dependabot/composer/doctrine/inflector-tw-1.0or-tw-2.0
- dev-dependabot/composer/phpunit/phpunit-tw-6.0or-tw-8.0
- dev-dependabot/composer/gecko-packages/gecko-php-unit-tw-2.0or-tw-3.0
This package is auto-updated.
Last update: 2024-12-22 07:18:15 UTC
README
Library helps to fix PHP code to conform Paysera PHP style guide.
Installation
Prerequisite
- Add
Paysera\\PhpCsFixerConfig\\Composer\\PhpCsFixerConfigProvider::copyPhpCs
script topost-install-cmd
andpost-update-cmd
or otherscripts
- just make sure this script is executed oncomposer install
.
Install and check
composer require --dev paysera/lib-php-cs-fixer-config
.- Make sure
php-cs-fixer.php
file is in project directory.
No need to install php-cs-fixer itself as this library comes with binary version of the fixer. This avoids requiring its dependencies inside your project, which could clash with existing ones.
To avoid duplication with php-cs-fixer library, it's named paysera-php-cs-fixer
.
php-cs-fixer.php files
php-cs-fixer.php
- all Paysera recommended fixers.php-cs-fixer-risky.php
- all risky fixers except recommendations (comment warnings).php-cs-fixer-safe.php
- all non risky fixers.
Migration mode
For new projects you can just use all the rules as usual.
For existing projects we recommend turning on the migration mode:
- Add call to
enableMigrationMode([])
toPayseraConventionsConfig
instance in yourphp-cs-fixer.php
file. - Run
{your-bin-dir}/php-cs-fixer
- it will give error with initial rule configuration to pass into that method. Just copy-and-paste it to yourphp-cs-fixer.php
file. - Enable one of the rules, apply fixes in the project, review and test them.
- Repeat with each new rule.
This allows to control which rules are enabled in the project thus letting manually tune the fixes already applied in the repository and forced for the new code. Also, your commits will be more focused as each of them will include only changes from a single fixer.
All rules are to be configured to allow easily spotting new rules in case they would be added (or removed) into the core.
Running fixer with tests
For comments or suggestions for developers you should use default php-cs-fixer.php
file with all the rules.
For automatic checks there might be some false-positives so php-cs-fixer-risky.php
should be used in such cases.
You can look at .travis.yml
file in this repository for integration with travis on each pull request of your repository
(this will run the checks only for changed files).
Usage
Run in project directory by command: {your-bin-dir}/php-cs-fixer fix /path/to/code --verbose --dry-run --diff
Use --config=php-cs-fixer.php
flag for custom configuration.
If /path/to/code
is not defined php-cs-fixer
will run files from default src
directory excluding Test
folders.
--verbose
- show the applied rules. When using the txt format it will also display progress notifications.
A combination of --dry-run
and --diff
will display a summary of proposed fixes, leaving your files unchanged.
--format
option for the output format. Supported formats are txt
(default one), json
, xml
and junit
.
More information: PHP CS Fixer