doctrine/coding-standard

Doctrine Coding Standard

Installs: 4 330

Dependents: 13

Suggesters: 0

Stars: 5

Watchers: 17

Forks: 6

Type:phpcodesniffer-standard

1.0.0 2017-08-20 01:30 UTC

README

Build Status Total Downloads Latest Stable Version

The PHP_CodeSniffer ruleset to check that repositories are following the standards defined by the our team.

Standards

We use PSR-1 and PSR-2 with some exceptions/differences (✅ are the implemented sniffs):

  • Keep the nesting of control structures per method as small as possible
  • Add spaces between assignment, control and return statements
  • Prefer early exit over nesting conditions
  • ✅ Align equals (=) signs
  • ✅ Add spaces around a concatenation operator $foo = 'Hello ' . 'World!';
  • ✅ Add spaces around a negation if condition if ( ! $cond)
  • ✅ Add spaces around a return type declaration function () : void {}
  • ✅ Add spaces after a type cast $foo = (int) '12345';

Installation

You have two possibilities to use the Doctrine Coding Standard with PHP_CodeSniffer in a particular project.

1. As a composer dependency of your project

You can install the Doctrine Coding Standard as a composer dependency to your particular project. Just add the following block to your project's composer.json file:

$ php composer require doctrine/coding-standard:~1.0

Then you can use it like:

$ ./vendor/bin/phpcs --standard=Doctrine /path/to/some/file/to/sniff.php

You might also do automatic fixes using phpcbf:

$ ./vendor/bin/phpcbf --standard=Doctrine /path/to/some/file/to/sniff.php

2. Global installation

You can also install the Doctrine Coding Standard globally:

$ composer global require doctrine/coding-standard:~1.0

Then you can use it like:

$ phpcs --standard=Doctrine /path/to/some/file/to/sniff.php

You might also do automatic fixes using phpcbf:

$ phpcbf --standard=Doctrine /path/to/some/file/to/sniff.php

Testing

If you are contributing to the Doctrine Coding Standard and want to test your contribution, you just need to execute PHPCS with the tests folder and ensure it matches the expected report:

$ ./vendor/bin/phpcs tests/input --report=summary --report-file=phpcs.log; diff tests/expected_report.txt phpcs.log