Skip to content

Commit 63d57bd

Browse files
committed
[DowngradePhp81] Reference MHASH_* constants by name in DowngradeHashAlgorithmXxHashRector to fix PHP 8.5 deprecation
1 parent f154b8b commit 63d57bd

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
final class DowngradeHashAlgorithmXxHashRector extends AbstractRector
2525
{
2626
/**
27-
* @var array<string, int>
27+
* Constants are referenced by name, as the MHASH_* constants are deprecated since PHP 8.5
28+
*
29+
* @var array<string, string>
2830
*/
2931
private const array HASH_ALGORITHMS_TO_DOWNGRADE = [
30-
'xxh32' => MHASH_XXH32,
31-
'xxh64' => MHASH_XXH64,
32-
'xxh3' => MHASH_XXH3,
33-
'xxh128' => MHASH_XXH128,
32+
'xxh32' => 'MHASH_XXH32',
33+
'xxh64' => 'MHASH_XXH64',
34+
'xxh3' => 'MHASH_XXH3',
35+
'xxh128' => 'MHASH_XXH128',
3436
];
3537

3638
private const string REPLACEMENT_ALGORITHM = 'md5';
@@ -167,7 +169,7 @@ private function getHashAlgorithm(array $args): ?string
167169

168170
private function mapConstantToString(string $constant): string
169171
{
170-
$mappedConstant = array_search(constant($constant), self::HASH_ALGORITHMS_TO_DOWNGRADE, true);
172+
$mappedConstant = array_search(ltrim($constant, '\\'), self::HASH_ALGORITHMS_TO_DOWNGRADE, true);
171173

172174
return $mappedConstant !== false ? $mappedConstant : $constant;
173175
}

0 commit comments

Comments
 (0)