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

Breadcrumb

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

function ObjectMemberCommaSniff::process

Process the tokens that this sniff is listening for.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.:

int $stackPtr The position in the stack where: the token was found.

Return value

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php, line 50

Class

ObjectMemberCommaSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Objects

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
    if ($tokens[$prev]['code'] === T_COMMA) {
        $error = 'Last member of object must not be followed by a comma';
        $fix = $phpcsFile->addFixableError($error, $prev, 'Found');
        if ($fix === true) {
            $phpcsFile->fixer
                ->replaceToken($prev, '');
        }
    }
}
RSS feed
Powered by Drupal