*/ public function register() { return Collections::phpOpenTags(); } /** * Processes this test, when one of its tokens is encountered. * * @since 9.3.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 int|void Integer stack pointer to skip forward or void to continue * normal file processing. */ public function process(File $phpcsFile, $stackPtr) { // Don't do anything if the warning has already been thrown or is not necessary. if ($this->examine === false) { return ($phpcsFile->numTokens + 1); } $phpVersion = \phpversion(); // Don't do anything if the PHPCS version used is above the minimum recommended version. if (\version_compare($phpVersion, self::MIN_RECOMMENDED_VERSION, '>=')) { $this->examine = false; return ($phpcsFile->numTokens + 1); } if (\version_compare($phpVersion, self::MIN_SUPPORTED_VERSION, '<')) { $isError = true; $message = 'IMPORTANT: Please be advised that the minimum PHP version the PHPCompatibility standard supports is %s. You are currently using PHP %s. Please upgrade your PHP installation. The recommended version of PHP for PHPCompatibility is %s or higher.'; $errorCode = 'Unsupported_' . MessageHelper::stringToErrorCode(self::MIN_SUPPORTED_VERSION); $replacements = [ self::MIN_SUPPORTED_VERSION, $phpVersion, self::MIN_RECOMMENDED_VERSION, ]; } else { $isError = false; $message = 'IMPORTANT: Please be advised that for the most reliable PHPCompatibility results, PHP %s or higher should be used. Support for lower versions will be dropped in the foreseeable future. You are currently using PHP %s. Please upgrade your PHP installation to version %s or higher.'; $errorCode = 'BelowRecommended_' . MessageHelper::stringToErrorCode(self::MIN_RECOMMENDED_VERSION); $replacements = [ self::MIN_RECOMMENDED_VERSION, $phpVersion, self::MIN_RECOMMENDED_VERSION, ]; } $message .= DisableSniffMsg::create('PHPCompatibility.Upgrade.LowPHP', $errorCode); MessageHelper::addMessage($phpcsFile, $message, 0, $isError, $errorCode, $replacements); $this->examine = false; // No need to look at this file again. return ($phpcsFile->numTokens + 1); } }