This repository contains the ruleset for the PHP code we develop at FLYERALARM. It mostly consists of PSR-2 with some custom additions. The rules are enforced with the help of squizlabs/PHP_CodeSniffer
- Variable names must be in lowerCamelCase
- Yoda conditions are forbidden
- Unit tests with @expectedException must contain @expectedExceptionMessage annotation
- Return type annotations (@return) must only contain one of scalar type or object (e.g. no "@return string|null")
- Exceptions messages must not contain exclamation marks or full stops
- Keywords GOTO and EVAL are forbidden
- Underscores in namespaces are forbidden
- Classtype suffixes like Interface, Abstract or Trait are forbidden (e.g. LoggerInterface)
To prepare run command:
make
To test ruleset run command:
make test
Add as composer dev dependency:
composer config repositories.flyeralarm/php-code-validator git https://github.com/flyeralarm/php-code-validator.git
composer require --dev flyeralarm/php-code-validator
Embed code sniffer in your Makefile. To intend please use tabs instead of spaces.
Usage: vendor/bin/php-code-validator <...>
Example Makefile:
test:
vendor/bin/php-code-validator src/ tests/
composer update flyeralarm/php-code-validator
make test
- Ensure the path to PHP Code Sniffer is configured - open configuration manual
- Open settings:
Mac:PhpStorm
>Preferences
>Editor
>Inspections
>PHP
Windows & Linux:File
>Settings
>Editor
>Inspections
>PHP
\ - Activate/Tick checkbox for
PHP Code Sniffer validation
- Click on the item
PHP Code Sniffer validation
to open its settings on the right hand side - Choose "Custom" for „Coding standard:“ and click on
...
on the right hand side - Select Path to ruleset. This would be something like <YOUR_APP_ROOT>/vendor/flyeralarm/coding-guidelines/ruleset.xml
- Confirm dialogs by pressing
ok
On a side note: We are searching for talented people to join our various teams of developers in multiple locations