bondforge / coding-standard
Shared PHP CS Fixer configuration and custom fixers for BondForge projects.
Requires
- php: >=8.3
- friendsofphp/php-cs-fixer: ^3.95
Requires (Dev)
- phpunit/phpunit: ^13.0
README
Shared PHP CS Fixer configuration and custom fixers for BondForge projects.
The headline feature is the BondForge/braces_position fixer — a superset of
php-cs-fixer's built-in braces_position that adds a next_line value for
functions_opening_brace, forcing the opening brace of every function and method
onto its own line (Allman style), including for multi-line signatures:
public function foo(int $a, int $b) { // ... } public function bar( int $a, int $b, ) { // ... }
Installation
composer require --dev bondforge/coding-standard
If the package is not published to Packagist, add the repository to the consuming
project's composer.json first:
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/BondForge/coding-standard" }
]
}
Usage
Create a .php-cs-fixer.dist.php in your project root that requires the shared
config:
<?php declare(strict_types=1); return require __DIR__ . '/vendor/bondforge/coding-standard/.php-cs-fixer.bondforge.php';
By default it scans bin/, public/, src/ and tests/ (whichever exist)
relative to the current working directory.
Customising the scanned paths
Define $finder before the require and the shared config will use it instead
of the default:
<?php declare(strict_types=1); $finder = (new PhpCsFixer\Finder()) ->in([__DIR__ . '/src', __DIR__ . '/lib']) ->append([__FILE__]); return require __DIR__ . '/vendor/bondforge/coding-standard/.php-cs-fixer.bondforge.php';
Then run it as usual:
vendor/bin/php-cs-fixer fix
The BondForge/braces_position rule
functions_opening_brace accepts a third value beyond the built-in fixer's
options:
| Value | Behaviour |
|---|---|
same_line |
Brace stays on the signature line. |
next_line_unless_newline_at_signature_end |
Brace goes to the next line, unless the signature already wraps. |
next_line (BondForge addition) |
Brace always goes to its own line, wrapped or not (Allman). |
All other options (classes_opening_brace, control_structures_opening_brace,
etc.) behave exactly like the built-in fixer and default to the same values
PSR-12 uses.
Development
composer install composer test # run the fixer's unit tests composer cs # lint this package with its own ruleset
License
MIT. src/Fixer/Basic/BracesPositionFixer.php is derived from php-cs-fixer's
BracesPositionFixer (© Fabien Potencier and Dariusz Rumiński, MIT). See
LICENSE.