You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A custom PHP_CodeSniffer standard that enforces opinionated type and docblock rules with auto-fixing capabilities.
Requirements
php >= 7.2
squizlabs/php_codesniffer 3.13+ || 4.x
Installation
# Per project:
$ composer require ycodetech/phpcs-standard
# Globally
$ composer global require ycodetech/phpcs-standard
Sniffs
yCodeTech.Commenting.DocblockFormat
Enforces proper spacing and formatting in docblocks.
Rules
Fixable?
All docblock tags must have exactly 1 space between each element.
✔️
The type and variable in any tag must be separated by a space.
✔️
@return tags must be preceded by exactly 1 empty line.
✔️
Violation Codes:
yCodeTech.Commenting.DocblockFormat.TagSpacing
yCodeTech.Commenting.DocblockFormat.ReturnSpacing
Examples:
✔️ Valid: Exactly 1 space between tag elements
❌ Invalid: Multiple spaces between tag elements
/** * @param string $name The name parameter * @throws Exception If something goes wrong * @see SomeClass For more information * @var string * @copyright Copyright (c) year, Name */
/** * @param string $name The name parameter * @throws Exception If something goes wrong * @see SomeClass For more information * @var string * @copyright Copyright (c) year, Name */
✔️ Valid: Exactly 1 space between type and variable
❌ Invalid: 0 spaces between type and variable
/** * @param string $name The name parameter */
/** * @param string$name The name parameter */
✔️ Valid: Exactly 1 empty line before @return tag
❌ Invalid: 0 empty lines before @return tag
/** * @param string $name The name parameter * * @return string */
/** * @param string $name The name parameter * @return string */
✔️ Valid: Exactly 1 empty line before @return tag
❌ Invalid: Multiple empty lines before @return tag
/** * @param string $name The name parameter * * @return string */
/** * @param string $name The name parameter * * * * @return string */
yCodeTech.Commenting.FunctionComment
Functions that return a value must have a @return docblock tag (nested anonymous function and closure returns will be ignored).
Rules
Fixable?
Notes
Functions with non-void return types (string, bool, etc.) must have a @return tag.
✔️
Fixes with a mixed return type.
Magic methods (e.g. __construct, __get, etc.) are exempt.
Functions with void return types must NOT have @return tags, except generator functions.
✔️
Most magic methods are exempt, except for those that return void:
__construct,
__destruct,
__clone,
__set,
__unset,
__wakeup, and
__unserialize.
/** * Get formatted string. * * @param string $input The input string */publicfunctionformatString(string$input): string
{
}
✔️ Valid: No @return for void function
❌ Invalid: @return tag on void function
/** * Process data without returning anything. * * @param array $data The data to process */publicfunctionprocessData(array$data): void
{
}
/** * Process data without returning anything. * * @param array $data The data to process * * @return void */publicfunctionprocessData(array$data): void
{
}
✔️ Valid: @return tag for generator function
❌ Invalid: Missing @return tag for generator function