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

Breadcrumb

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

function ClassDeclarationSniff::process

Same name in this branch
  1. 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php \Drupal\Sniffs\Classes\ClassDeclarationSniff::process()
  2. 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php \PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff::process()
  3. 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php \PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff::process()
  4. 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php \PHP_CodeSniffer\Standards\PEAR\Sniffs\Classes\ClassDeclarationSniff::process()

Processes this test, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

Return value

void

Overrides ClassDeclarationSniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php, line 29

Class

ClassDeclarationSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes

Code

public function process(File $phpcsFile, $stackPtr) {
    // We want all the errors from the PSR2 standard, plus some of our own.
    parent::process($phpcsFile, $stackPtr);
    // Check that this is the only class or interface in the file.
    $nextClass = $phpcsFile->findNext([
        T_CLASS,
        T_INTERFACE,
    ], $stackPtr + 1);
    if ($nextClass !== false) {
        // We have another, so an error is thrown.
        $error = 'Only one interface or class is allowed in a file';
        $phpcsFile->addError($error, $nextClass, 'MultipleClasses');
    }
}
RSS feed
Powered by Drupal