*/ protected $targetFunctions = ['version_compare' => \true]; /** * The operators which are no longer supported. * * Note: operators are case-sensitive, values should be lowercase. * * @since 10.0.0 * * @var array */ private $unsupportedOperators = ['' => \true, 'l' => \true, 'g' => \true, 'e' => \true, '!' => \true, 'n' => \true]; /** * Do a version check to determine if this sniff needs to run at all. * * @since 10.0.0 * * @return bool */ protected function bowOutEarly() { return ScannedCode::shouldRunOnOrAbove('8.1') === \false; } /** * Process the parameters of a matched function. * * @since 10.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in the stack. * @param string $functionName The token content (function name) which was matched. * @param array $parameters Array with information about the parameters. * * @return int|void Integer stack pointer to skip forward or void to continue * normal file processing. */ public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) { $targetParam = PassedParameters::getParameterFromStack($parameters, 3, 'operator'); if ($targetParam === \false) { return; } $tokens = $phpcsFile->getTokens(); $textStartTokens = Tokens::$stringTokens; $textStartTokens += Tokens::$heredocTokens; $accepted = $textStartTokens; $accepted += Tokens::$emptyTokens; $hasNonText = $phpcsFile->findNext($accepted, $targetParam['start'], $targetParam['end'] + 1, \true); if ($hasNonText !== \false) { // Found a non text-string token. Ignore as undetermined. return; } $textStringStart = $phpcsFile->findNext($textStartTokens, $targetParam['start'], $targetParam['end'] + 1); if ($textStringStart === \false) { // Shouldn't be able to happen, but just in case. return; // @codeCoverageIgnore } $contents = TextStrings::getCompleteTextString($phpcsFile, $textStringStart); if (isset($this->unsupportedOperators[$contents]) === \false) { // Either never supported or still supported. return; } $phpcsFile->addError('version_compare() no longer supports operator abbreviations since PHP 8.1. Found: %s', $textStringStart, 'Found', [$targetParam['clean']]); } }