GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - brainbits/phpcs-standard: The brainbits PHP coding standard.

BranchesTags
Open more actions menu

Latest commit

 

History

115 Commits
115 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
Brainbits
Brainbits
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.releaserc
.releaserc
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpcs.xml.dist
phpcs.xml.dist
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

brainbits Coding Standard

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 aligned
  • Generic.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 – forbids throw new with PHP's built-in global exceptions (\Exception, \ErrorException and the SPL exceptions like \RuntimeException, \InvalidArgumentException, …). Only direct throw 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

  1. Clone repository
  2. Install dependencies
    composer install
  3. Configure standard:
    {install-dir}/vendor/bin/phpcs --config-set default_standard Brainbits
    
  4. Execute:
    {install-dir}/vendor/bin/phpcs {src-dir}

In Project

  1. Add the standard to your project:
    composer require brainbits/phpcs-standard
  2. Configure standard:
    vendor/bin/phpcs --config-set default_standard Brainbits
  3. Execute:
    vendor/bin/phpcs {src-dir}

In Project with Ruleset Customization

  1. Add the standard to your project:
    composer require brainbits/phpcs-standard
  2. Create phpcs.xml (see https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage)
    1. Include brainbits ruleset:
      <rule ref="Brainbits" />
    2. Add default src-dir:
      <file>{src-dir}</file>
    3. Tweak to your needs, for example add rules or disable rules included in the brainbits standard.
  3. 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.

About

The brainbits PHP coding standard.

Resources

Readme
MIT license
Activity
Custom properties

Stars

1 star

Watchers

3 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.