class DisallowEmptyFunctionSniff
Hierarchy
- class \SlevomatCodingStandard\Sniffs\Functions\DisallowEmptyFunctionSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of DisallowEmptyFunctionSniff
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Functions/ DisallowEmptyFunctionSniff.php, line 13
Namespace
SlevomatCodingStandard\Sniffs\FunctionsView source
class DisallowEmptyFunctionSniff implements Sniff {
public const CODE_EMPTY_FUNCTION = 'EmptyFunction';
/**
* @return array<int, (int|string)>
*/
public function register() : array {
return [
T_FUNCTION,
];
}
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param int $functionPointer
*/
public function process(File $phpcsFile, $functionPointer) : void {
$tokens = $phpcsFile->getTokens();
if (FunctionHelper::isAbstract($phpcsFile, $functionPointer)) {
return;
}
if (FunctionHelper::getName($phpcsFile, $functionPointer) === '__construct') {
$propertyPromotion = TokenHelper::findNext($phpcsFile, Tokens::$scopeModifiers, $tokens[$functionPointer]['parenthesis_opener'] + 1, $tokens[$functionPointer]['parenthesis_closer']);
if ($propertyPromotion !== null) {
return;
}
}
$firstContent = TokenHelper::findNextExcluding($phpcsFile, T_WHITESPACE, $tokens[$functionPointer]['scope_opener'] + 1, $tokens[$functionPointer]['scope_closer']);
if ($firstContent !== null) {
return;
}
$phpcsFile->addError('Empty function body must have at least a comment to explain why is empty.', $functionPointer, self::CODE_EMPTY_FUNCTION);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DisallowEmptyFunctionSniff::CODE_EMPTY_FUNCTION | public | constant | ||
DisallowEmptyFunctionSniff::process | public | function | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * |
Overrides Sniff::process |
DisallowEmptyFunctionSniff::register | public | function | * | Overrides Sniff::register |