> */ protected $newAlgorithms = [ 'md2' => [ '5.2' => false, '5.3' => true, ], 'ripemd256' => [ '5.2' => false, '5.3' => true, ], 'ripemd320' => [ '5.2' => false, '5.3' => true, ], 'salsa10' => [ '5.2' => false, '5.3' => true, ], 'salsa20' => [ '5.2' => false, '5.3' => true, ], 'snefru256' => [ '5.2' => false, '5.3' => true, ], 'sha224' => [ '5.2' => false, '5.3' => true, ], 'joaat' => [ '5.3' => false, '5.4' => true, ], 'fnv132' => [ '5.3' => false, '5.4' => true, ], 'fnv164' => [ '5.3' => false, '5.4' => true, ], 'gost-crypto' => [ '5.5' => false, '5.6' => true, ], 'sha512/224' => [ '7.0' => false, '7.1' => true, ], 'sha512/256' => [ '7.0' => false, '7.1' => true, ], 'sha3-224' => [ '7.0' => false, '7.1' => true, ], 'sha3-256' => [ '7.0' => false, '7.1' => true, ], 'sha3-384' => [ '7.0' => false, '7.1' => true, ], 'sha3-512' => [ '7.0' => false, '7.1' => true, ], 'crc32c' => [ '7.3' => false, '7.4' => true, ], 'murmur3a' => [ '8.0' => false, '8.1' => true, ], 'murmur3c' => [ '8.0' => false, '8.1' => true, ], 'murmur3f' => [ '8.0' => false, '8.1' => true, ], 'xxh32' => [ '8.0' => false, '8.1' => true, ], 'xxh64' => [ '8.0' => false, '8.1' => true, ], 'xxh3' => [ '8.0' => false, '8.1' => true, ], 'xxh128' => [ '8.0' => false, '8.1' => true, ], ]; /** * Constructor. * * @since 10.0.0 * * @return void */ public function __construct() { $this->targetFunctions = $this->hashAlgoFunctions; } /** * Should the sniff bow out early for specific PHP versions ? * * @since 10.0.0 * * @return bool */ protected function bowOutEarly() { return 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 void */ public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) { $algo = $this->getHashAlgorithmParameter($functionName, $parameters); if (empty($algo) || \is_string($algo) === false) { return; } // Bow out if not one of the algorithms we're targetting. if (isset($this->newAlgorithms[$algo]) === false) { return; } // Check if the algorithm used is new. $itemInfo = [ 'name' => $algo, ]; $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); } /** * Handle the retrieval of relevant information and - if necessary - throwing of an * error for a matched item. * * @since 10.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the relevant token in * the stack. * @param array $itemInfo Base information about the item. * * @return void */ protected function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) { $itemArray = $this->newAlgorithms[$itemInfo['name']]; $versionInfo = $this->getVersionInfo($itemArray); if (empty($versionInfo['not_in_version']) || ScannedCode::shouldRunOnOrBelow($versionInfo['not_in_version']) === false ) { return; } $this->addError($phpcsFile, $stackPtr, $itemInfo, $versionInfo); } /** * Generates the error for this item. * * @since 10.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the relevant token in * the stack. * @param array $itemInfo Base information about the item. * @param string[] $versionInfo Array with detail (version) information * relevant to the item. * * @return void */ protected function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $versionInfo) { // Overrule the default message template. $this->msgTemplate = "The '%s' hash algorithm is not present in PHP version %s or earlier"; $msgInfo = $this->getMessageInfo($itemInfo['name'], $itemInfo['name'], $versionInfo); $phpcsFile->addError($msgInfo['message'], $stackPtr, $msgInfo['errorcode'], $msgInfo['data']); } }