iwf-web / php-coding-standard
Configs & RuleSets for PHP Code
Fund package maintenance!
D3strukt0r
Patreon
Open Collective
Buy Me A Coffee
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/iwf-web/php-coding-standard
Requires (Dev)
This package is auto-updated.
Last update: 2025-12-19 08:35:28 UTC
README
Custom PHP-CS-Fixer rule sets for consistent code style across IWF projects.
Rule Sets
This package provides two rule sets:
| Rule Set | Description |
|---|---|
@IWF/standard |
Non-risky coding style rules for consistent formatting |
@IWF/standard:risky |
Risky rules that may change code behavior (use with caution) |
Both rule sets build upon the excellent @PhpCsFixer rule set (which includes @Symfony and @PSR12) with customizations tailored for IWF projects.
Getting Started
Prerequisites
- PHP 8.2 or higher
- PHP-CS-Fixer ^3.0
Installation
composer require --dev iwf-web/php-coding-standard
Usage
Create a .php-cs-fixer.dist.php file in your project root:
<?php declare(strict_types=1); require_once __DIR__.'/vendor/autoload.php'; use IWF\CodingStandard\IWFRiskySet; use IWF\CodingStandard\IWFSet; use PhpCsFixer\Config; use PhpCsFixer\Finder; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; return new Config() ->registerCustomRuleSets([ new IWFSet(), new IWFRiskySet(), ]) ->setFinder(Finder::create() ->in(__DIR__) ) ->setParallelConfig(ParallelConfigFactory::detect()) ->setRiskyAllowed(true) ->setRules([ '@IWF/standard' => true, '@IWF/standard:risky' => true, ]) ;
Run the fixer:
# Check for violations (dry run) vendor/bin/php-cs-fixer fix --dry-run --diff # Fix violations vendor/bin/php-cs-fixer fix
Rule Customizations
@IWF/standard
Key customizations over the base @PhpCsFixer rule set:
- No Yoda style - Uses natural comparison order (
$value === nullinstead ofnull === $value) - Strict types at top - No blank line after opening tag to keep
declare(strict_types=1);at the very top - Simplified class ordering - Only requires traits to be placed first in classes
- Preserved DocBlocks - Single-line DocBlocks are preserved;
@inheritDocis not removed - Trailing commas everywhere - In arrays, arguments, parameters, and match expressions
- PHPUnit flexibility - Does not require
@coversannotations on test classes
@IWF/standard:risky
Key customizations over the base @PhpCsFixer:risky rule set:
- PHPUnit assertions - Uses
self::for test case static method calls - No forced strict types - Relies on PHPStan for type safety instead of enforcing
declare(strict_types=1); - Flexible data providers - Does not enforce naming conventions for PHPUnit data providers
- Ignored comment tags - Preserves
php-cs-fixer-ignoreandtodocomments
Contributing
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
Versioning
We use SemVer for versioning. For available versions, see the tags on this repository.
Authors
All authors can be found in the AUTHORS.md file.
Contributors can be found in the CONTRIBUTORS.md file.
See also the full list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Acknowledgments
A list of used libraries and code with their licenses can be found in the ACKNOWLEDGMENTS.md file.