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.
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');
- 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}
- 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}
- 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
- Slevomat https://github.com/slevomat/coding-standard
- Doctrine https://github.com/doctrine/coding-standard
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 testMIT, see LICENSE.