brainbits / phpcs-standard
Brainbits Coding Style
Package info
github.com/brainbits/phpcs-standard
Type:phpcodesniffer-standard
pkg:composer/brainbits/phpcs-standard
Requires
- php: ^8.4
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- doctrine/coding-standard: ^14.0
- slevomat/coding-standard: ^8.23
- squizlabs/php_codesniffer: ^4.0
Requires (Dev)
- phpunit/phpunit: ^13.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-03 17:13:05 UTC
README
PHP_CodeSniffer ruleset used at brainbits. It is based on the Doctrine Coding Standard (which includes the Slevomat Coding Standard), relaxes a few of its rules and adds a custom sniff.
Requires PHP 8.4 or newer and PHP_CodeSniffer 4. The name of the standard is Brainbits.
Differences to Doctrine
Disabled rules:
Generic.Formatting.MultipleStatementAlignment.NotSame– assignments don't need to be alignedGeneric.Formatting.SpaceAfterNot.Incorrect– no space required after!Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed– multi-line arrays with a single item are allowed
Additional rules:
-
Brainbits.Exception.GlobalException– forbidsthrow newwith PHP's built-in global exceptions (\Exception,\ErrorExceptionand the SPL exceptions like\RuntimeException,\InvalidArgumentException, …). Only directthrow new …statements are checked. Extend the exceptions in your own namespace instead:// error throw new \RuntimeException('Not found'); // ok final class NotFound extends \RuntimeException {} throw new NotFound('Not found');
How to Use
Global
- Clone repository
- Install dependencies
composer install
- Configure standard:
{install-dir}/vendor/bin/phpcs --config-set default_standard Brainbits - Execute:
{install-dir}/vendor/bin/phpcs {src-dir}
In Project
- Add the standard to your project:
composer require brainbits/phpcs-standard
- Configure standard:
vendor/bin/phpcs --config-set default_standard Brainbits
- Execute:
vendor/bin/phpcs {src-dir}
In Project with Ruleset Customization
- Add the standard to your project:
composer require brainbits/phpcs-standard
- Create phpcs.xml (see https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage)
- Include brainbits ruleset:
<rule ref="Brainbits" />
- Add default src-dir:
<file>{src-dir}</file>
- Tweak to your needs, for example add rules or disable rules included in the brainbits standard.
- Include brainbits ruleset:
- Execute:
vendor/bin/phpcs
Used Code Styles
- Slevomat https://github.com/slevomat/coding-standard
- Doctrine https://github.com/doctrine/coding-standard
Development
composer install vendor/bin/phpunit # unit tests of the custom sniffs vendor/bin/phpcs # check this repository with its own standard vendor/bin/phpcs --basepath=. --report=summary --report-file=phpcs.log --standard=Brainbits `find tests/Brainbits/input/* | sort`; diff -u tests/Brainbits/expected_report.txt phpcs.log # ruleset integration test
License
MIT, see LICENSE.