flaconi / coding-standard
Flaconi Coding Standard for PHP_CodeSniffer
Installs: 42 942
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 22
Forks: 1
Open Issues: 0
Type:phpcodesniffer-standard
Requires
- php: ^7.4 || ^8.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.0
- doctrine/coding-standard: ^9.0
- escapestudios/symfony2-coding-standard: ^3.11
- slevomat/coding-standard: ^7.0
- squizlabs/php_codesniffer: ^3.3
Requires (Dev)
- jangregor/phpstan-prophecy: ^0.8.0
- johnkary/phpunit-speedtrap: ^4.0
- phpstan/phpstan: ^0.12.0
- phpstan/phpstan-phpunit: ^0.12.0
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^8.0 || ^9.5
- pyrech/composer-changelogs: ^1.6
- roave/security-advisories: dev-latest
README
Flaconi Coding Standard for PHP_CodeSniffer provides sniffs that fall for now in one category:
- Test - improving the code style of phpunit test cases
Table of contents
- Sniffs included in this standard
- Installation
- How to run the sniffs
- Fixing errors automatically
- Suppressing sniffs locally
- Contributing
Sniffs included in this standard
🔧 = Automatic errors fixing
Test - improving the code style of phpunit test cases
FlaconiCodingStandard.Test.UseMethodPrefixInTestcase 🔧
- Checks for
@test
and force to usetest
Prefix
FlaconiCodingStandard.Test.UseStaticCallsForAssertInTestcase 🔧
Reports usage of non static assert method class
Installation
The recommended way to install Flaconi Coding Standard is through Composer.
composer require --dev flaconi/coding-standard
How to run the sniffs
You can choose one of two ways to run only selected sniffs from the standard on your codebase:
Choose which sniffs to run
Mention Flaconi Coding Standard in your project's ruleset.xml
:
<?xml version="1.0"?> <ruleset name="AcmeProject"> <rule ref="vendor/flaconi/coding-standard/src/ruleset.xml"><!-- relative path to your ruleset.xml --> <!-- sniffs to exclude --> </rule> </ruleset>
When running phpcs
on the command line, use the --sniffs
option to list all the sniffs you want to use separated by a comma:
vendor/bin/phpcs --standard=ruleset.xml \
--sniffs=FlaconiCodingStandard.Test.UseStaticCallsForAssertInTestcase,FlaconiCodingStandard.Test.UseMethodPrefixInTestcase \
--extensions=php --encoding=utf-8 --tab-width=4 -sp src tests
Or write your own ruleset.xml by referencing the selected sniffs. This is a sample ruleset.xml:
<?xml version="1.0"?> <ruleset name="AcmeProject"> <config name="installed_paths" value="../../flaconi/coding-standard"/><!-- relative path from PHPCS source location --> <rule ref="FlaconiCodingStandard.Test.UseMethodPrefixInTestcase"/> <!-- other sniffs to include --> </ruleset>
Then run the phpcs
executable the usual way:
vendor/bin/phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
Fixing errors automatically
Sniffs in this standard marked by the 🔧 symbol support automatic fixing of coding standard violations. To fix your code automatically, run phpcbf instead of phpcs:
vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
Always remember to back up your code before performing automatic fixes and check the results with your own eyes as the automatic fixer can sometimes produce unwanted results.
Contributing
To make this repository work on your machine, clone it and run these two commands in the root directory of the repository:
composer install
composer code-style
composer tests
After writing some code and editing or adding unit tests, run phing again to check that everything is OK:
composer code-style
composer tests
We are always looking forward for your bugreports, feature requests and pull requests. Thank you.