*/ public function register() { $targets = Collections::functionCallTokens(); $targets[\T_ISSET] = \T_ISSET; $targets[\T_UNSET] = \T_UNSET; return $targets; } /** * Processes this test, when one of its tokens is encountered. * * @since 8.2.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in * the stack passed in $tokens. * * @return void */ public function process(File $phpcsFile, $stackPtr) { if (ScannedCode::shouldRunOnOrBelow('7.2') === false) { return; } $tokens = $phpcsFile->getTokens(); $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false ) { return; } if (($tokens[$stackPtr]['code'] === \T_STRING || isset(Collections::ooHierarchyKeywords()[$tokens[$stackPtr]['code']])) && isset($tokens[$nextNonEmpty]['parenthesis_owner']) === true ) { // Function declaration, not a function call. return; } $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true); if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) { return; } $data = []; switch ($tokens[$stackPtr]['code']) { case \T_ISSET: $data[] = 'calls to isset()'; $errorCode = 'FoundInIsset'; break; case \T_UNSET: $data[] = 'calls to unset()'; $errorCode = 'FoundInUnset'; break; default: $data[] = 'function calls'; $errorCode = 'FoundInFunctionCall'; break; } $phpcsFile->addError( 'Trailing commas are not allowed in %s in PHP 7.2 or earlier', $lastInParenthesis, $errorCode, $data ); } }