Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DisallowEmptyFunctionSniff.php

function DisallowEmptyFunctionSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $functionPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Functions/DisallowEmptyFunctionSniff.php, line 30

Class

DisallowEmptyFunctionSniff

Namespace

SlevomatCodingStandard\Sniffs\Functions

Code

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);
}
RSS feed
Powered by Drupal