diff --git a/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHash/Fixture/fixture_fully_qualified_constant.php.inc b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHash/Fixture/fixture_fully_qualified_constant.php.inc new file mode 100644 index 00000000..45542bc3 --- /dev/null +++ b/rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHash/Fixture/fixture_fully_qualified_constant.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php b/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php index 435a9553..5a2304e8 100644 --- a/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php +++ b/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php @@ -24,13 +24,15 @@ final class DowngradeHashAlgorithmXxHashRector extends AbstractRector { /** - * @var array + * Constants are referenced by name, as the MHASH_* constants are deprecated since PHP 8.5 + * + * @var array */ private const array HASH_ALGORITHMS_TO_DOWNGRADE = [ - 'xxh32' => MHASH_XXH32, - 'xxh64' => MHASH_XXH64, - 'xxh3' => MHASH_XXH3, - 'xxh128' => MHASH_XXH128, + 'xxh32' => 'MHASH_XXH32', + 'xxh64' => 'MHASH_XXH64', + 'xxh3' => 'MHASH_XXH3', + 'xxh128' => 'MHASH_XXH128', ]; private const string REPLACEMENT_ALGORITHM = 'md5'; @@ -167,7 +169,7 @@ private function getHashAlgorithm(array $args): ?string private function mapConstantToString(string $constant): string { - $mappedConstant = array_search(constant($constant), self::HASH_ALGORITHMS_TO_DOWNGRADE, true); + $mappedConstant = array_search(ltrim($constant, '\\'), self::HASH_ALGORITHMS_TO_DOWNGRADE, true); return $mappedConstant !== false ? $mappedConstant : $constant; }