wayofdev / cs-fixer-config
๐งน Adds custom rule-sets to PHP CS Fixer for consistent coding standards.
Fund package maintenance!
wayofdev
Installs: 38 886
Dependents: 18
Suggesters: 1
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 13
Requires
- php: ^8.1
- friendsofphp/php-cs-fixer: ^3.57
Requires (Dev)
- ergebnis/phpunit-slow-test-detector: ^2.14
- pestphp/pest: ^2.34
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.11
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-phpunit: ^1.4
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^10.5
- psalm/plugin-phpunit: ^0.19
- rector/rector: ^1.1
- roave/infection-static-analysis-plugin: ^1.35
- vimeo/psalm: ^5.24
- dev-master
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.61
- v1.2.60
- v1.2.59
- v1.2.58
- v1.2.57
- v1.2.56
- v1.2.55
- v1.2.54
- v1.2.53
- v1.2.52
- v1.2.51
- v1.2.50
- v1.2.49
- v1.2.48
- v1.2.47
- v1.2.46
- v1.2.45
- v1.2.44
- v1.2.43
- v1.2.42
- v1.2.41
- v1.2.40
- v1.2.39
- v1.2.38
- v1.2.37
- v1.2.36
- v1.2.35
- v1.2.34
- v1.2.33
- v1.2.32
- v1.2.31
- v1.2.30
- v1.2.29
- v1.2.28
- v1.2.27
- v1.2.26
- v1.2.25
- v1.2.24
- v1.2.23
- v1.2.22
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.19
- v1.1.18
- v1.1.17
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/phpstan-packages
- dev-renovate/actions-cache-4.x
- dev-renovate/ergebnis-phpunit-slow-test-detector-2.x-lockfile
- dev-renovate/vimeo-psalm-5.x-lockfile
- dev-renovate/pestphp-pest-2.x-lockfile
- dev-renovate/pestphp-pest-3.x
- dev-renovate/wayofdev-gh-actions-3.x
- dev-renovate/wagoid-commitlint-github-action-6.x
- dev-renovate/friendsofphp-php-cs-fixer-3.x-lockfile
- dev-renovate/rector-rector-1.x-lockfile
- dev-renovate/shivammathur-setup-php-2.x
- dev-release-please--branches--master--components--php-cs-fixer-config
- dev-feat/auto-merge
- dev-codesee-arch-diagram-workflow-1678375134679
This package is auto-updated.
Last update: 2024-11-17 15:14:27 UTC
README
PHP CS Fixer Config
Wrapper with pre-defined rules around the PHP-CS-Fixer package โ A tool to automatically fix PHP Coding Standards issues.
This repository aims to provide a standardized way to apply coding standards across multiple projects, ensuring consistency and adherence to best practices. By using predefined rulesets, it simplifies the setup process and allows teams to quickly integrate PHP-CS-Fixer into their development workflow.
If you like/use this package, please consider โญ๏ธ starring it. Thanks!
๐ Custom Rulesets
WayOfDev\PhpCsFixer\Config\RuleSets\DefaultRuleset::class
Based on @Symfony
ruleset
- Used by
@wayofdev
organization
WayOfDev\PhpCsFixer\Config\RuleSets\ExtendedPERSet::class
Based on @PER-CS2.0
ruleset
- Used by
@buggregator
and@cycle
organizations
๐ฟ Installation
โ Using composer
Require as dependency:
composer req --dev wayofdev/cs-fixer-config
๐ Configuration
โ Setup
-
Create PHP file and name it
.php-cs-fixer.dist.php
and place it inside root directory of project. It will be recognized by PHP CS Fixer automatically. -
Example contents of
.php-cs-fixer.dist.php
file:<?php declare(strict_types=1); use WayOfDev\PhpCsFixer\Config\ConfigBuilder; use WayOfDev\PhpCsFixer\Config\RuleSets\DefaultSet; require_once 'vendor/autoload.php'; $config = ConfigBuilder::createFromRuleSet(new DefaultSet()) ->inDir(__DIR__ . '/src') ->inDir(__DIR__ . '/tests') ->addFiles([__FILE__]) ->getConfig() ; $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php-cs-fixer.cache'); return $config;
โ Composer Script
-
Add
scripts
section tocomposer.json
:{ "scripts": { + "cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff", + "cs:fix": "php vendor/bin/php-cs-fixer fix -v" } }
โ Git
-
Place
.build
folder file into.gitignore
+/.build/ /vendor/
โ Makefile
-
If you are using
Makefile
, create aMakefile
with alint-php
andlint-diff
targets:+APP_RUNNER ?= php +APP_COMPOSER ?= $(APP_RUNNER) composer + +prepare: + mkdir -p .build/php-cs-fixer +.PHONY: prepare +lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer + $(APP_COMPOSER) cs:fix +.PHONY: lint-php +lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied + $(APP_COMPOSER) cs:diff +.PHONY: lint-diff
Or, you can check for one of our pre-configured Makefile
from any of these repositories:
https://github.com/wayofdev/php-cs-fixer-config/blob/master/Makefile
https://github.com/wayofdev/laravel-package-tpl/blob/master/Makefile
โ GitHub Actions
-
To use this package in GitHub Actions, add a
coding-standards.yml
workflow to your repository:--- on: # yamllint disable-line rule:truthy pull_request: branches: - master push: branches: - master name: ๐งน Fix PHP coding standards jobs: coding-standards: timeout-minutes: 4 runs-on: ${{ matrix.os }} concurrency: cancel-in-progress: true group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} strategy: matrix: os: - ubuntu-latest php-version: - '8.1' dependencies: - locked permissions: contents: write steps: - name: โ๏ธ Set git to use LF line endings run: | git config --global core.autocrlf false git config --global core.eol lf - name: ๐ ๏ธ Setup PHP uses: shivammathur/setup-php@2.30.4 with: php-version: ${{ matrix.php-version }} extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter ini-values: error_reporting=E_ALL coverage: none - name: ๐ฆ Check out the codebase uses: actions/checkout@v4.1.5 - name: ๐ ๏ธ Setup problem matchers run: | echo "::add-matcher::${{ runner.tool_cache }}/php.json" - name: ๐ค Validate composer.json and composer.lock run: composer validate --ansi --strict - name: ๐ Get composer cache directory uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 - name: โป๏ธ Restore cached dependencies installed with composer uses: actions/cache@v4.0.2 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- - name: ๐ฅ Install "${{ matrix.dependencies }}" dependencies with composer uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 with: dependencies: ${{ matrix.dependencies }} - name: ๐ ๏ธ Prepare environment run: make prepare - name: ๐จ Run coding standards task run: composer cs:fix env: PHP_CS_FIXER_IGNORE_ENV: true - name: ๐ค Commit and push changed files back to GitHub uses: stefanzweifel/git-auto-commit-action@v5.0.1 with: commit_message: 'style(php-cs-fixer): lint php files and fix coding standards' branch: ${{ github.head_ref }} commit_author: 'github-actions <github-actions@users.noreply.github.com>' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Or, you can check for one of our pre-configured workflows from any of these repositories:
https://github.com/wayofdev/php-cs-fixer-config/blob/master/.github/workflows/coding-standards.yml
๐ป Usage
Fix coding standards by simply running console command:
โ Directly
vendor/bin/php-cs-fixer fix -v
โ Via Composer Script
To use via composer script commands:
-
Fixes code to follow coding standards using php-cs-fixer:
composer cs:diff
-
Runs php-cs-fixer in dry-run mode and shows diff which will by applied:
composer cs:fix
โ Using Makefile
To use with Makefile
-
Fixes code to follow coding standards using php-cs-fixer:
make lint-php
-
Runs php-cs-fixer in dry-run mode and shows diff which will by applied:
make lint-diff
๐ Security Policy
This project has a security policy.
๐ Want to Contribute?
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
- ๐ค Suggest a feature
- ๐ Report an issue
- ๐ Improve documentation
- ๐จโ๐ป Contribute to the code
You are more than welcome. Before contributing, kindly check our contribution guidelines.
๐ซก Contributors
๐ Social Links
- Twitter: Follow our organization @wayofdev and the author @wlotyp.
- Discord: Join our community on Discord.
๐งฑ Resources
-
Full documentation about all fixers is available here - PHP-CS-Fixer configuration UI
-
The official PHP-CS-Fixer documentation