function ClassDeclarationSniff::process
Same name in this branch
- 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php \Drupal\Sniffs\Classes\ClassDeclarationSniff::process()
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php \PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff::process()
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php \PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff::process()
- 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
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\ClassesCode
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');
}
}