Written Additional PHPCS Rules for Detecting Code Quality Issues & Even Automatically fixing it using PHPCBF
- Clone this repo
git clone https://github.com/pushpenderindia/rtSniffs ~/.composer/vendor/squizlabs/php_codesniffer/src/Standards/rtSniffs
- Check whether
rtSniffs
is getting detected byphpcs
phpcs -i
2.1 Expected Output (Should contain rtSniffs):
➜ rtSniffs git:(main) ✗ phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, rtSniffs, WordPress-VIP-Go, WordPressVIPMinimum, PHPCompatibility, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityWP, Modernize, NormalizedArrays, Universal, PHPCSUtils, VariableAnalysis, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra
- Detecting Code Quality Issues in current directory
phpcs --standard=rtSniffs .
- Fixing Issues using
phpcbf
phpcs --standard=rtSniffs .
- rtSniffs is in developmental stage, so use
phpcs
command only, don't rely onphpcbf
for autofix.
-
Sniffs.Commenting.MissingReturnTagSniff
: Checks if docblock contains@return
Type -
Sniffs.Spacing.ExcessiveBlankLineSniff
: Detects more than one consecutive blank line. -
Sniffs.Spacing.MissingSpaceBeforeCommentSniff
: Checking if there is a space before start of single line comment. -
Sniffs.Spacing.MissingSpaceAfterDeclarationSniff
: Ensure there is a blank line after function, loop, or if statement declarations. - ValidateFunctionReturnType: Validate the function return type and if exceptions are not handled then throw warning